Rick Ellis - 27 August 2008 08:27 PM
steelaz—I don’t think we should use empty() there, because a numeric zero submitted will cause empty() to return TRUE. That’s not a desired behavior.
I believe the bug is due to empty strings being set, rather then considered NULL. Here’s my proposed fix:
Open Form_validation.php
At line 321, change this:
if (isset($_POST[$field]))
To this:
if (isset($_POST[$field]) AND $_POST[$field] != "")
The above fix makes the form no longer use custom error messages as set by set_message(). It reverts back to the original, and as far as I can tell still throws an error on an empty field that is not required but has further validation rules if something is entered.
With fix in place:
“The last_name field must have a value.” displays
Without fix:
“Field Required” displays
My fix follows more of the line of steelaz. Can you foresee any issues with the following at line 483?
if ( ! in_array('required', $rules, TRUE) AND $postdata == '')
$fields = array(
array('field' => 'last_name',
'label' => '',
'rules' => 'trim|htmlspecialchars|required|min_length[1]|max_length[50]'),
array('field' => 'middle_initial',
'label' => '',
'rules' => 'trim|htmlspecialchars|exact_length[1]|alpha'),
// **SNIP**
$this->form_validation->set_rules($fields);
Last name properly errors out with my fix in.
Middle Initial only shows an error if I enter a 1 or something non-alpha. If I enter nothing all is well.