CodeIgniter Forums
Codeigniter AJAX Form guide/tutorial. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Codeigniter AJAX Form guide/tutorial. (/showthread.php?tid=31303)

Pages: 1 2


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-14-2010

[eluser]variouspixels[/eluser]
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



gemmes


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-14-2010

[eluser]Ivar89[/eluser]
May I suggest google...


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-14-2010

[eluser]variouspixels[/eluser]
I tried Google before I posted.


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-14-2010

[eluser]Flemming[/eluser]
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(); }


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-14-2010

[eluser]variouspixels[/eluser]
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

thanks


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-14-2010

[eluser]bryantAXS[/eluser]
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.


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-14-2010

[eluser]variouspixels[/eluser]
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.


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-18-2010

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


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-18-2010

[eluser]slowgary[/eluser]
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.


Codeigniter AJAX Form guide/tutorial. - El Forum - 06-19-2010

[eluser]pbreit[/eluser]
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.