CodeIgniter Forums

Full Version: CI form validation with input data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.
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
@Wouter 60

Thank you so much