always enter default value in empty field [message #68] |
Sun, 11 June 2006 19:21 ![Go to next message Go to previous message](/theme/default/images/down.png) |
semcycle
Messages: 8 Registered: June 2006 Location: Michigan, USA
|
Junior Member |
|
|
first off - thanks Tony , what an awesome framework !!
i have poked around in the samples & am now setting up an app of my own, where i ran into the following. Not sure if this is a bug or intended behavior, but here it is with my workaround:
in the mysql table:
column `errors` INT NOT NULL DEFAULT '0'
in the table class:
$fieldspec['errors'] = array('type' => 'integer',
'size' => 11,
'default' => '0');
This is not a required field. If this field is left empty upon adding a new record, a fatal error - column can not be null results.
workaround:
In std.validation.class.inc the default value gets inserted only for required fields.
i added the following lines to have this happen for all empty entries:
around line 77:
if (strlen($fieldvalue) == 0) {
// field is empty - is it allowed to be?
if (isset($fieldspec['required'])) {
if (isset($fieldspec['autoinsert'])
or isset($fieldspec['auto_increment'])) {
// value will be filled in later, so continue
} elseif (isset($fieldspec['default'])) {
$fieldvalue = $fieldspec['default'];
} else {
// '"$fieldname cannot be blank'
$this->errors[$fieldname] = getLanguageText('sys0020', $fieldname);
} // if
} // if
if ($fieldspec['type'] == 'date' or $fieldspec['type'] == 'datetime'
or $fieldspec['type'] == 'timestamp') {
if (isset($fieldspec['infinityisnull'])) {
$fieldvalue = '9999-12-31';
} // if
} // if
if ($fieldspec['type'] == 'boolean') {
$fieldvalue = $fieldspec['false'];
} // if
// ******************** added lines ***************************
// enter the default value for any empty field that has one set, not just required ones
if (isset($fieldspec['default'])) {
$fieldvalue = $fieldspec['default'];
} // if
// ********************* end of added lines *********************
// nothing left to validate, so return now
return $fieldvalue;
} // if
I am especially interested to find out if you think this may break other expected behavior.
Sem Abrahams
www.semcycle.com
|
|
|