Re: Re: DO Formbuilder: crosslinks (checkboxes) Problem solved !! ?
| From: | Justin Patrin | Date: | Mon, 06 Dec 2004 19:05:17 +0000 |
| Subject: | Re: Re: DO Formbuilder: crosslinks (checkboxes) Problem solved !! ? | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16052@lists.php.net to get a copy of this message | ||
On Mon, 6 Dec 2004 15:16:24 +0100, Alexander Petri <alex.petri@gmx.de> wrote:
> so i finally updated the method &_generateForm(.....)
>
> LINE (around) 956 to around 971:
>
> foreach ($all_options as $key=>$value) {
> /*$crossLinksElement =
> HTML_QuickForm::createElement('checkbox', $groupName.'[]', null, $value);
> $crossLinksElement->updateAttributes(array('value'
> => $key));
> if (in_array($key, $selected_options)) {
> $crossLinksElement->setChecked(true);
> }*/
> if(in_array($key, $selected_options)){
> // echo "direct from DB ---- > ";
> $crossLinkDefaults[$groupName][$key]=$key;
> // echo $key."<br>\n";
> }
> // old one:
> // $crossLinksElement =
> $this->_createCheckbox($groupName.'['.$key.']', $value, $key,
> in_array($key,
> $selected_options));
> $crossLinksElement =
> $this->_createCheckbox($groupName.'['.$key.']', $value, $key, false);
> $element[] = $crossLinksElement;
> }
>
> and LINE 1185 (the last Lines in this method)
>
> // Assign default values to the form
> //print_r($crossLinkDefaults);
> if(isset($crossLinkDefaults))
> $formValues=array_merge($formValues,$crossLinkDefaults);
> $form->setDefaults($formValues);
> return $form;
>
> this works great to me....
>
Please create a bug report in the PEAR bug report system and put a
link to a patch so that we can see the changes easier. You can also
e-mail the patch to me if you don't have somewhere to put it up.
http://pear.php.net/bugs/report.php?package=DB_DataObject_FormBuilder
As for setDefaults, are you *sure* it's doing anything? I seem to
remember it not working for checkboxes... Actually, testing using this
code:
include 'HTML/QuickForm.php';
$form = new HTML_QuickForm();
$form->addElement('checkbox', 'ch');
$form->setDefaults(array('ch' => true));
$form->display();
The checkbox is not checked. It has a *value* of what you put in
setDefaults, but it is not checked. In this case, we have no reason to
add the crosslinks to the setDefaults call.
>
> "Alexander Petri" <alex.petri@gmx.de> schrieb im Newsbeitrag
> news:20041206134621.48238.qmail@pb1.pair.com...
>
>
> > i pointed out another error:
> > if you have a crosslink, the value "checked" is not setted by the method
> > setDefaults
> > there is an array $selected_options which is directly from the DB
> > and is putted directly into the method _createCheckbox
> > so it works like setConstants i guess...
> >
> > but Justin Patrin wrote:
> > "Leaving a POST in the browser history can easily cause problems"
> >
> > i dont know really what this means, or if it is a problem for my thoughts
> to
> > solve
> > the "crosslink Problem"
> >
> >
> > "Alexander Petri" <alex.petri@gmx.de> schrieb im Newsbeitrag
> > news:20041206123756.2383.qmail@pb1.pair.com...
> > > The Problem was
> > > if you do a submit on a form with crosslinks
> > > and you want to show the form again (direct after it is submitted)
> > > you will recognize that the "checked"-value on crosslinks are lost...
> > > (i described the problem a short time ago in this mailing list)
> > >
> > >
> > > Now i hope i solved this Problem:
> > > in file DB/DataObject/FormBuilder.php Linie (around) 962
> > > i changed this line:
> > >
> > > $crossLinksElement = $this->_createCheckbox($groupName.'[]', $value,
> $key,
> > > in_array($key, $selected_options));
> > >
> > > to this line:
> > >
> > > $crossLinksElement =
> > > $this->_createCheckbox($groupName.'['.$key.']',
> > $value,
> > > $key, in_array($key, $selected_options));
> > >
> > > note this: '['.$key.']'
> > >
> > > now it seems to work...
> > > it would be great to update the whole class if there are no side
> > effects...
> > >
> > > another point are triple links LINE (around)1041
> > >
> > > $tripleLinksElement = $this->_createCheckbox('__tripleLink_' .
> > > $tripleLink['table'] . '[' . $key1 . '][]',
> > >
> > > i guess there should be also:
> > >
> > > $tripleLinksElement = $this->_createCheckbox('__tripleLink_' .
> > > $tripleLink['table'] . '[' . $key1 .
> > > ']['.$key2.']',
>
--
Justin Patrin