Form Validation To Check Min and Max values in two fields - 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: Form Validation To Check Min and Max values in two fields (/showthread.php?tid=57564) |
Form Validation To Check Min and Max values in two fields - El Forum - 03-23-2013 [eluser]hema[/eluser] Hi All, I am having a form which is having min_cost and max_cost as two fields. max_cost field value should always be bigger than min_cost. How can i do this CI validation Following is my code Code: $this->form_validation->set_rules('cost-min', 'Cost Min', 'required|numeric'); // should always be lower than cost-max Above code is not working, is there anything i can do? Form Validation To Check Min and Max values in two fields - El Forum - 03-23-2013 [eluser]TheFuzzy0ne[/eluser] Your rules: Code: $this->form_validation->set_rules('cost-min', 'Cost Min', 'required|numeric'); // should always be lower than cost-max In your controller, add the following method. Code: function _more_than($str, $field='') I've not tested it, but it should give you something to go on. Hope this helps. Form Validation To Check Min and Max values in two fields - El Forum - 03-23-2013 [eluser]hema[/eluser] thanks man, its working fine after remove this part Code: if ( ! form_error('cost-min')) { Form Validation To Check Min and Max values in two fields - El Forum - 03-23-2013 [eluser]TheFuzzy0ne[/eluser] Sorry. I've corrected the code so it should work now. I put a '!' in there that shouldn't be there, which was why it was causing you problems. That line ensures it doesn't run if there's a validation error from the first field. it's pointless running it if we don't have a valid cost-min. Please use the new code. That should work fine now. |