Welcome Guest, Not a member yet? Register   Sign In
Field validation on maximum value
#1

[eluser]mdcode[/eluser]
I am trying to run validation on a form field where it checks to see if the number entered is higher than the number of records entered into the table in the database, but even though the tested value is higher, the error message does not display.

Code:
$this->form_validation->set_message('max_number', 'The value entered in the %s field must be a valid feedback item ID number.');

//some more code

/* set rule according to the selection of whether or not it is a repeat incident */
        $last_id = $this->db->count_all('feedback');
        
        if ( ($this->input->post('repeat') > 0) OR ($this->input->post('previous_id') > $last_id) )
        {
        $this->form_validation->set_rules('previous_id', 'Previous Complaint ID', 'required|min_length[1]|is_natural_no_zero|integer|max_number');
        }

Mucho appreciate any help.
#2

[eluser]verynewtothis[/eluser]
callback function are called like this:

Code:
$this->form_validation->set_rules('previous_id', 'Previous Complaint ID', 'required|min_length[1]|is_natural_no_zero|integer|callback_max_number');
#3

[eluser]mdcode[/eluser]
Thanks for your reply, but this hasn't happened before... Even if I place callback_ in front of the condition, validation seemingly fails to run on this field at all. I really don't understand what's going on with it since I have tested the clause with PHP.

The posted field value and variable is set.
$this->db->count_all() is returning a variable.
Actions based on these values return as expected, except the validation... :question:
#4

[eluser]verynewtothis[/eluser]
could you post the code for max_number callback function?
#5

[eluser]mdcode[/eluser]
Thanks again for the prompting... you saying what you have done, as me re-reading the documentation, I've realized what I have done - the previous one (which is working) I have added into the form validation files directly, where as here I needed to write an extra function (as per your prompting).

All is okay now.




Theme © iAndrew 2016 - Forum software by © MyBB