Codeigniter AJAX Form guide/tutorial.

Hi all,

I would like to validate input fields after the user hits the tab key using AJAX. Can anyone point me to a tutorial showing a basic guide to doing this with Codeigniter?

many thanks


May I suggest google...

I tried Google before I posted.

I would recommend jquery validate

by default it is 'lazy' but apparently you can make it 'eager' so it will validate on tab/focus change:

$('#myform').validate({ onfocusout: function(element) { $(element).valid(); }

I am probably going to implement a non codeigniter way of doing this. The form is CI but I guess I am going to have to use jquery validate or similar. Sad


It sounds like your getting CI validation and jQuery validation confused. If you want a form field to validate when the user clicks "tab" (before the form is submitted) you will have to use a javascript solution, such as jQuery. CI can only validate your data on the server side of things, after the form has been submitted.

PHP CI Validation is first thing I got working correctly. I am now using the validate plugin to validate with JS separately.

I did want to use AJAX to ask PHP to validate the page. Not neccessary but I thought this was 'best practice'. Its been a while since I used AJAX with regular PHP but I used to get JS to access a separate process_form.php script which handled validation based on $_POST/$_GET variables. Memory hazy I don't remember exactly. I wanted to do this with CI.

My current setup will have to do for now.

[eluser]Ngua Go[/eluser]
from Google !

Client-side validation is a nice touch but can't be trusted. I agree with the recommendation to juse use the jquery validation plugin since it's very flexible and does a great job. You could take the time to put something AJAX together, but I can't agree that it's really the "best practice", since the user can still disable javascript or can change the value of a field after it's been validated and checked out. The idea with client-side validation is to save the user the frustration of having to resubmit the form. The jquery validation plugin takes care of that end, then the server-side validation assures that it's actually valid.

As many have stated, first make sure you are validating data on the server side. Then, if you want to do some JavaScript validation for convenience or usability, use a package like Jquery.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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