Cjax Framework


Creating functinality using generic Cjax API.

Demonstrates how to launch a login screen while manipuilating elements. This is only a generic "flow" example and it is not a complete login script. The showcase of the ajax functionality more than anything. This sample also demonstrates how to do some element manipulation in the backend. On this example elements are being manipulated and re-used.

Examples

PHP
<?php 

//Initial Code

//Loads file resources/html/login.html onto the overlay
//Adds event listerner to button1 so when you click it
//it submit/posts the form to url 'ajax.php?ajax_login/handler'

$overlay $ajax->overlay('resources/html/login.html');

$overlay->click('#button1'$ajax->form('ajax.php?ajax_login/handler'));

//assigns the overlay to the click event on achor element 'a_login'
//so when you click the link the overlay is displayed
$ajax->click('#a_login'$overlay);


//Controller
class ajax_login {

    function 
handler($username$password)
    {
        
$ajax ajax();

        if(!
$username) {
            return  
$ajax->err 'Enter your username.';
        }
        if(!
$password) {
            return 
$ajax->err 'Enter your password.';
        }

        
$ajax->success("Hello $username, You haved successfully logged in.");

        
$ajax->flush('#a_login'); //clear previous click events from element
        
$ajax->overlay();//clear overlay from the screen

        
$ajax->login_div "Hello $username!, Logout Now..";
        
$ajax->insert('#login_div','#a_login',true); // places the login button inside the login_div container

        
$ajax->click('#a_login'$ajax->call('ajax.php?ajax_login/logout')); // adds the ajax link to a_login
        
$ajax->a_login 'Logout';  //changes the login text to logout

    
}

    function 
logout()
    {
        
$ajax ajax();
        
$ajax->flush('#a_login'); //clear previous click events from element
        
$ajax->success("You haved logged out.");
        
$ajax->a_login 'Login'//changes the text back to 'login'
        
$ajax->insert('#login_now_area','#a_login'); //moves the logout link to the bottom
        
$ajax->login_div 'Login Again..'//updates the login_div container text

        //This is exactly the example as the first line in the Initial code but with different syntax
        
$overlay $ajax->overlay('resources/html/login.html');
        
$link $ajax->click('button1',$ajax->form('ajax.php?ajax_login/handler','form1'));
        
$overlay->callback($link);
        
$ajax->click('a_login'$overlay);
    }
}

?>

Try it


Login


View Code Used

Previous Topic:  Previous Class    ·   Top of Page   ·   Demos Home   ·  

CodeIgniter  ·  Copyright © 2006 - 2012  ·  Cjax