Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Bug Reports » always enter default value in empty field
always enter default value in empty field [message #68] Sun, 11 June 2006 19:21 Go to previous message
semcycle is currently offline  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
 
Read Message
Read Message
Next Topic: Audit_trn task_id field too small
Goto Forum:
  


Current Time: Mon Nov 25 08:40:07 EST 2024

Total time taken to generate the page: 0.00932 seconds