• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TUTORIAL] *UPDATED* Using jQuery and CI for a AJAX Login (v0.2) + example rar

#31
[eluser]Schumacher[/eluser]
hey,
great example on how to do jquery in CI, that is just what im looking into atm Smile

I just got something on my mind, if i want to have the form_validation send back, can i just put it into the $output or ? So that the user gets the same error messages wether they have javascript turned on or not.

Great job. !

#32
[eluser]suba[/eluser]
Thank you so much.
your tutorial is great!!

#33
[eluser]Isern Palaus[/eluser]
[quote author="Schumacher" date="1271132405"]hey,
great example on how to do jquery in CI, that is just what im looking into atm Smile

I just got something on my mind, if i want to have the form_validation send back, can i just put it into the $output or ? So that the user gets the same error messages wether they have javascript turned on or not.

Great job. ![/quote]

You can return the message you want in the json, where says the error message. You can put there anything :-). Try it, it will work!

The AJAX function in jQuery shows the message that the controller sends to it, there is nothing predefined.

#34
[eluser]Isern Palaus[/eluser]
[quote author="suba" date="1271148560"]Thank you so much.
your tutorial is great!![/quote]

Thank you, glad you like it! Smile

PS: Lol, it has 14k views! :O

#35
[eluser]nhantam[/eluser]
controllers/checkForm.php (class)

Code:
function checkEmail() {
                
        global $cgfvars;
        
        $this->validation->set_error_delimiters ( '<div class="error">', '</div>' );    
                
        $rules['email'] = 'trim|required|valid_email|max_length[100]|xss_clean|callback_checkMemberEmailExist';
        $fields['email'] = $cgfvars ['_re_email_regis_'];
                
        //echo $fields['email'];
        
        $this->validation->set_rules( $rules );
        $this->validation->set_fields( $fields );
        
        // check valid date
        $validDate = TRUE;
        
        
        if ($this->validation->run () == FALSE || $validDate == FALSE) {
            echo "MSG";
            echo $this->validation->email_error;
            //return false;
        } else {
            echo "OK";
        }
        
        
    }

views/register.html


Code:
$(document).ready(function() {
    $('#email').mouseup(function() {
        $.ajax({
            url: 'mywebfolder/checkForm/checkEmail/',
            type: 'post',
            data: 'email='+$("#email").val(),
            success: function(result) {
                alert(result);
                //$('#email_error').attr('innerHTML', result);
            }
        });
    });
});

Code:
&lt;form name="registerMember" method="post" action="{$_domain_url_}register/memberRegister/"&gt;
&lt;input id="email" style="width: 210px" class="field" name="email" value="{$email}" type="text" /&gt;

I use ajax, jquery to check email before form(registerMember) submit,
but my function alert(result) show whole html of file register.html such as image following:
[IMG=http://img691.imageshack.us/img691/3685/errorfq.gif][/IMG]
[Image: errorfq.th.gif]

Could you help me ? check my file error. Thank of all.

#36
[eluser]Unknown[/eluser]
Hi,

Great Tutorial! Thanks a lot!

#37
[eluser]Oozooo[/eluser]
Could someone help me out ?

If i return my json value like this:

Code:
$data = array(    'success' =>    'no',
                  'message' =>    'The email or password you provided are wrong.');

$output = json_encode($data);

it all works.

If i would return it like this:

Code:
$data = array(    'success' =>    'no',
                  'message' =>    'The email or password
                                   you provided are wrong.');

$output = json_encode($data);

It doesnt work (note the line-break). The jquery-form plugin doesn't seem to validate the json string.

As stated in the jquery-form documentation:
'json': if dataType == 'json' the server response will be evaluted and passed to the 'success' callback, if specified

I just can't get it. Already tryed removing /n from the output.

I need it to work that way because i want to return the validation_errors() instead of a static line.

#38
[eluser]afro[/eluser]
Hey guys, i would like your assistance in handling a problem with Ajax.
I have four fields in my view and i want when one of the field in filled, the other three field are load from the database
automatically using the Ajax, the page should refresh and load the three fields when the staffid field losses focus.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.