Re: [QUICKFORM] Question about QuickForm
| From: | Bertrand Mansion | Date: | Tue, 26 Aug 2003 09:14:32 +0000 |
| Subject: | Re: [QUICKFORM] Question about QuickForm | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-7418@lists.php.net to get a copy of this message | ||
<stanis@sibfair.nsk.su> wrote :
> Hi!
>
> I did a quick test of QuickForm (QuickForm_example.php in docs/ dir)
> and have a question. If I pass a single variable to the page, say
> 'yes=1', which is not part of the form, why is the form redisplayed
> automatically with red messages indicating required fields, etc? I am
> wondering how to go about coding simple add/modify forms where the
> mode (i.e. add/modify) and record ids will be passed into the page via
> the GET method. In OOHForms, we had to manually validate the form on
> the basis of the existence of certain hidden variables (which
> indicated that the form was actually posted), but
> in this example, the error messages are displayed regardless of
> whether the validate method is called or not.
As the method for the form is GET, if QuickForm notices that values are
passed using GET (in the url), it will validate the form. The same applies
to POST.
The workaround is to set an hidden element in the form and testing for its
existence before calling validate:
$form->setConstants(array('formname' => 'loginform'));
$form->addElement('hidden', 'formname');
...
If ($form->getElementValue('formname') == 'loginform' &&
$form->validate())
...
This way, validate will never be called if the submitted form does not
contain a hidden field 'formname'. We use setConstants() so that the user
can't cheat and override the element value. We use getElementValue() because
it returns the constant value if any.
The other solution is to wait for the HTML_QuickForm_Controller class that's
coming soon :)
Bertrand Mansion
Mamasam