![]() |
How to implement JS validations through CodeIgniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to implement JS validations through CodeIgniter (/showthread.php?tid=6533) |
How to implement JS validations through CodeIgniter - El Forum - 03-03-2008 [eluser]Sumon[/eluser] Hello all, I am very new in CodeIgnIter world. But within this time i love CI very much. I am used to validate a form like this.... JAVASCRIPT FUNCTION -------------------------------------------------------------------- function Validation() { if(this.frmRegistration.txtFullName.value=="") { alert("Please enter full name."); this.frmRegistration.txtFullName.focus(); return false; } return true; } -------------------------------------------------------------------- How shall i implement the same in CI. Please help me to get out..... thanks, Sumon How to implement JS validations through CodeIgniter - El Forum - 03-03-2008 [eluser]xwero[/eluser] You have to use the validation library to do this Code: $rules['txtFullName'] = 'required'; How to implement JS validations through CodeIgniter - El Forum - 03-03-2008 [eluser]nmweb[/eluser] Are you looking for something like this: http://h1368840.stratoserver.net/2008/02/16/update-to-jquerykohana-forge-validation/ So have the library generate the js? Otherwise you still have to write the js yourself. How to implement JS validations through CodeIgniter - El Forum - 03-03-2008 [eluser]adamp1[/eluser] I would highly disapprove of JS validation. First off if the user doesn't have JS turned on your form won't be validated. Also they could change the JS to allow invalid input. It would be fine if you used it in conjunction with the CI validation, but don't use it on its own. How to implement JS validations through CodeIgniter - El Forum - 03-04-2008 [eluser]Sumon[/eluser] Thanks for your help. I like to know something more. Here is my files ------------------------------------------------------- view_validate.php // inside view folder ------------------------------------------------------- echo form_open("JsValidation/ValidateMethod"); $data = array( 'name' => 'txtFullName', 'id' => 'txtFullName', 'value' => '', 'maxlength' => '100', 'size' => '50', 'style' => 'width:50%', ); echo form_input($data); echo form_submit('mysubmit', 'Submit Post!'); $rules['txtFullName'] = 'required'; $this->validation->set_rules($rules); $fields['txtFullName'] = 'full name'; $this->validation->set_fields($fields); ------------------------------------------------------- And here is my controller code ------------------------------------------------------- class JsValidation extends Controller { function JsValidation() { parent::Controller(); $this->load->helper("form"); $this->load->library('validation'); } function Validate() { $this->load->view("view_validate"); } } ------------------------------------------------------- Now my question is how to set and display error message. Anything to change in configuration file? Please help me to get out. How to implement JS validations through CodeIgniter - El Forum - 03-04-2008 [eluser]xwero[/eluser] You should add the rules and fields to the controller. To display the error all you have to do is Code: <?php echo $this->validation->error_string; ?> How to implement JS validations through CodeIgniter - El Forum - 03-04-2008 [eluser]Sumon[/eluser] I shall be highly happy if someone send me a complete example please. thanks, Sumon How to implement JS validations through CodeIgniter - El Forum - 03-04-2008 [eluser]xwero[/eluser] Code: /*------------------------------------------------------- |