[eluser]PeteSig[/eluser]
Hi
I've just begun using ci & am looking at the form validation class.
Going through the tutorial (expanding & changing as I go) I noticed that the set_value() function only returns input strings for those inputs with rules attached, those inputs with no rules attached (not being checked) don't have their content strings returned.
Ie, in the tutorial, if I set a rule for only 'username' & 'password' then if I use set_value() in the other inputs - passconf, email - any data held here doesn't get returned if I submit without entering 'username' & / or 'password' data.
Stepping through the code for set_value, it seems that if a validation object is set, then set_value will return only the string for inputs with rules (ie. which are part of the validation object). If no validation obj is created, then set_value will return input string values. But what about returning strings for inputs with no rules set, when a validation obj is set!?!?! You get the default empty string!
The orig, in form_helper.php at line 652:
Code:
if ( ! function_exists('set_value'))
{
function set_value($field = '', $default = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
if ( ! isset($_POST[$field]))
{
return $default;
}
return form_prep($_POST[$field], $field);
}
return form_prep($OBJ->set_value($field, $default), $field);
}
}
should be something like this (which seems to fix the issue):
Code:
if ( ! function_exists('set_value'))
{
function set_value($field = '', $default = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
if ( ! isset($_POST[$field]))
{
return $default;
}
return form_prep($_POST[$field], $field);
} <added next block>
else
{
if(! array_key_exists($field, $OBJ->_field_data))
{
if ( ! isset($_POST[$field]))
{
return $default;
}
return form_prep($_POST[$field], $field);
}
}<end of added block>
return form_prep($OBJ->set_value($field, $default), $field);
}
}
Is this a bug & should it be noted in the bug section for future inclusion??
Cheers
Pete