Re: HTML_Quickform hidden elements

From: Date: Fri, 27 Sep 2002 16:43:21 +0000
Subject: Re: HTML_Quickform hidden elements
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-9616@lists.php.net to get a copy of this message
Something like the code below will not work, because $counter is always 1. Why is $this->setValue($value) only done, if $tmp_val is null?
The reason is that when you pass a value as the third argument to addElement() it is to act as a default value, meaning it is only set if there is no other value for the element. In your case it will fill in $counter the first time the form shows up, but after the form is submitted it will take the $_POST value because that overrrides the default value. What you want is to use setConstants() which says set the value of the element to "x" no matter what $_POST/$_GET is. So, your script would look like: require_once("HTML/QuickForm.php"); $counter = $_POST["tmp_hidden"]; $tmp_constants['tmp_hidden'] = ++$counter; $form =& new HTML_QuickForm('tmp_form','POST'); $form->setConstants($tmp_constants); $form->addElement('hidden','tmp_hidden'); $form->addElement('submit','tmp_submit','Submit Form'); $form->display(); Cheers, -Jason

« previous php.pear.dev (#9616) next »