PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject_FormBuilder » Bug #5490

tinyint fields being forced to 0 when not being rendered

Details

Submitted2005-09-22 09:15 UTC
Fromdsanders at baselinesolutions dot com dot au
Assignedjustinpatrin
StatusClosed
PackageDB_DataObject_FormBuilder
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2005-09-22 09:15 UTC] dsanders at baselinesolutions dot com dot au

Description:
------------
Hi, more on booleans ... ;)

I have some tinyint fields in my db table that I don't want rendered in the form for certain reasons. When a form is submitted and passed to processForm() all of these fields are forced to 0. This is due to the addition of this code:
http://cvs.php.net/diff.php/pear/DB_DataObject_FormBuilder/FormBuilder.php?r1=1.110&r2=1.111&ty=u
which was in response to this bug:
http://pear.php.net/bugs/bug.php?id=3167
However I don't see how the previous foreach loop didn't take care of this bug?

Anyway to solve the problem of unrendered tinyint fields being updated, while still keeping the functionality as described in the previous bug report, I recommend the following patch:

@@ -2498,15 +2498,10 @@ class DB_DataObject_FormBuilder
}
}
foreach ($this->booleanFields as $boolField) {
- if (!isset($values[$boolField])) {
+ if (!isset($values[$boolField]) && in_array($boolField, $this->fieldsToRender)) {
$this->_do->$boolField = 0;
}
}
- foreach ($tableFields as $field => $type) {
- if ($type & DB_DATAOBJECT_BOOL && !isset($values[$field])) {
- $this->_do->$field = 0;
- }
- }

$dbOperations = true;
if ($this->validateOnProcess === true) {

The change on the first loop is to close up the gotchya in case someone forgets to take any bools out of their booleanFields array that they don't want to be modified.

Test script:
---------------
class DO_Some_table extends DB_DataObject
{
###START_AUTOCODE

var $hidden_bool; // int(3) not_null unsigned
var $shown_bool; // int(3) not_null unsigned
var $comments; // string(255)

###END_AUTOCODE

var $fb_booleanFields = array('shown_bool','hidden_bool');
// not entirely
var $fb_fieldsToRender = array('comments','shown_bool');
}