Re: QuickForm2 validation

From: Date: Tue, 25 May 2010 08:40:42 +0000
Subject: Re: QuickForm2 validation
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-30560@lists.php.net to get a copy of this message
Hi Anonymous, On 25.05.2010 12:15, Php Developer wrote:
Even if I added a rule, the user can still submit a form with an empty field. What would be the correct version of the following code: require_once "HTML/QuickForm2.php"; $form = new HTML_QuickForm2('test'); $fieldSet = $form->addFieldset()->setLabel('test'); $title = $fieldSet->addText('title')->setLabel('Title:'); $title->setValue("mytitle");
Here you override whatever value was submitted with your 'mytitle' value...
$title->addRule('required', "Please provide title");
...and when this rule runs it checks 'mytitle' and finds it valid. The correct way to set default values is $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
    'title'  => 'mytitle',
    'Letter' => 'my letter'
)));

« previous php.pear.general (#30560) next »