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 next 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
Re: always enter default value in empty field [message #69 is a reply to message #68] Mon, 12 June 2006 04:53 Go to previous message
AJM is currently offline  AJM
Messages: 2363
Registered: April 2006
Location: Surrey, UK
Senior Member
semcycle wrote on Mon, 12 June 2006 00:21

first off - thanks Tony , what an awesome framework !!

Thanks. It's gratifying to now that my humble efforts are not a complete waste of time. Smile

As for your error, if a field is defined as NOT NULL then by definition it *IS* required, but I take your point that if a default value has been defined then it should be used whenever no value has been input, required or not. I shall incorporate this fix in my next release.


Next Topic: Audit_trn task_id field too small
Goto Forum:
  


Current Time: Tue Oct 15 18:11:45 EDT 2024

Total time taken to generate the page: 0.01016 seconds