Re: Re: [QuickForm] Rules for a costum Form?

From: Date: Fri, 07 Jun 2002 11:00:35 +0000
Subject: Re: Re: [QuickForm] Rules for a costum Form?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1607@lists.php.net to get a copy of this message
le 6/06/02 18:20, Frank Thiel à thier6@gmx.de a écrit : > Hi, Bertrand. > Today i had time to make a new try. > >> just pass an array like this instead: >> >> $attributes = array('size' => 22, 'style' => 'WIDTH:183 >> px'); >> $form->addElement('text', 'ArticleHeadline', >> 'ArticleHeadline:',$attributes); > > That´s a very good idea. > >> You'd better try to isolate your problem by writing smaller tests. > > No i do have the same Problem like before. > Without $form->clearAllTemplates();, it works! > > Yes, that´s right. No here is a smaller codetest: > > <?php > require_once("HTML/QuickForm.php"); > $form = new HTML_QuickForm('frmTest', 'POST', $PHP_SELF); > $form->clearAllTemplates(); > $form->addElement('text', 'BannerIMG', 'BannerIMG:', > ''); > $form->addElement('submit', null, 'Submit'); > $form->addRule('BannerIMG', 'Dies ist ein Pflichtfeld', > 'required'); > if ($form->validate()) { > $form->freeze(); > } > $form->display(); > ?> Sorry, I forgot what your problem was :-) First, you might consider not using $PHP_SELF like that because it is a potential security problem. You should always use $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] or $_SERVER['PHP_SELF']. If you leave this parameter empty, it will default to the former. But you might already know that. Anyway, your problem is that you clear all templates so there is no way for QuickForm to know where it should display its error message. But the error message is there ! For instance, if you use this code : <?php require_once("HTML/QuickForm.php"); $form = new HTML_QuickForm('frmTest', 'POST'); $form->clearAllTemplates(); $form->addElement('text', 'BannerIMG', 'BannerIMG:'); $form->addElement('submit', null, 'Submit'); $form->addRule('BannerIMG', 'Dies ist ein Pflichtfeld', 'required'); if ($form->validate()) { $form->freeze(); } $form->display(); echo '<pre>'; var_dump($form->toArray()); echo '</pre>'; ?> You will notice that the error message is set as expected. The solution is to make your own element template with a placeholder for your error messages. You can also rely on javascript validation (not recommended) by using this line: $form->addRule('BannerIMG', 'Dies ist ein Pflichtfeld', 'required', '', 'client'); Tell me if I am clear enough. Bertrand Mansion Mamasam

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