Enum Type and 0 index. [message #391] |
Mon, 13 November 2006 08:19 |
johandewit
Messages: 25 Registered: May 2006 Location: Belgium
|
Junior Member |
|
|
File : includes/std.validation.class.inc
Funtion : validatefield
if ($fieldspec['type'] == 'enum') {
debugbreak();
// get enum array for this field
$enum = $this->caller->getValRep($fieldname);
// if we already have the value do not replace it
if (!in_array($fieldvalue, $enum)) {
// replace index number with text value
$fieldvalue = $enum[$fieldvalue];
} // if
} // if
Problem ; If $fieldvalue=0, where 0 = array_index, the function in_array returns TRUE instead of FALSE. The fieldarray is not replaced with the $enum[0] value, resulting in validation error.
See also http://be.php.net/manual/en/function.in-array.php#61491
Changing line 111 to if (!in_array($fieldvalue, $enum, true))
solves this, and the fieldvalue is rpelaced with $enum[0] as intended.
At the end of this function, the enum type is passed to the validateNumber, (default case branch) which always results in an error message.
I've attached a patch against version 1.17.0 which makes the enum field type working (in my situation).
Greetings
Johan
|
|
|