Re: Boolean values and DataObject_FormBuilder
| From: | Justin Patrin | Date: | Wed, 29 Sep 2004 17:47:52 +0000 |
| Subject: | Re: Boolean values and DataObject_FormBuilder | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14687@lists.php.net to get a copy of this message | ||
On Wed, 29 Sep 2004 15:41:03 +0200, John Toven <john@finansgruppen.net> wrote:
> Hi all,
>
> Any way to get DB_DataObject_FormBuilder to display checkboxes for
> boolean fields in forms (mysql tinyints)? I've tried adding the
> following code to the class extention
> (http://marc.theaimsgroup.com/?l=pear-dev&m=107163769701468&w=2) but
> with no luck. Any help much appreciated,
>
> John
>
> var $fb_booleanFields = array(
> 'fieldname' => 'descr',
> Etc...
> );
This doesn't need a fb_ since formbuilder isn't going to actually use
this value. Perhaps we should add boolean support directly to FB...
>
> function preGenerateForm()
> {
> $this->preDefElements = array();
> if (is_array($this->fb_booleanFields)) {
> foreach ($this->fb_booleanFields as $field=>$description) {
> $temp = &HTML_QuickForm::createElement('checkbox', $field,
> $this->fb_fieldLabels[$field], $description);
> $temp->setChecked($this->$field);
> $this->preDefElements[$field] = &$temp;
This one, however, needs an fb_
$this->fb_preDefElements[$field] = &$temp;
Make this change and it should work. :-)
> }
> }
> }
>
> function preProcess(&$values)
> {
> if (is_array($this->fb_booleanFields)) {
> foreach (array_keys($this->fb_booleanFields) as $field) {
>
> if ($values[$field] != 1) {
> $values[$field] = 0;
> }
> }
> }
> }
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--