• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI form validation with input data

#1
I have form which contain no of participant appeared and passed two text box.

In ci form validation how can i check passed participant should not be greater than the appeared. Please help me.
Reply

#2
You could use a callback.

https://www.codeigniter.com/user_guide/l...on-methods

Then in the callback function get the two post values, compare them, and if not correct, set an error message for the callback rule name.
Reply

#3
The form validation library has a rule for that.
Let's say the passing participant is field name "part_passing" and the appearing one has field name "part_appearing", then set the rules as follows:
PHP Code:
$this->form_validation->set_rules('part_passing','Passing participant','required|less_than_equal_to[part_appearing]');
$this->form_validation->set_rules('part_appearing','Appearing participant','required'); 

This makes both fields required, and the passing participant must be less than or equal to the appearing participant (which is the same is "not greater than"). Probably in your case, 'less_than' is better, to ensure that both fields will not be the same.

See documentation about the form validation library:
https://www.codeigniter.com/userguide3/l...ation.html
Reply

#4
@Wouter 60

Thank you so much
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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