Changes in QuickForm in CVS
| From: | Bertrand Mansion | Date: | Thu, 24 Oct 2002 15:06:39 +0000 |
| Subject: | Changes in QuickForm in CVS | ||
| Groups: | php.pear.dev php.pear.general | ||
| Request: | Send a blank email to pear-dev+get-10218@lists.php.net to get a copy of this message | ||
Hi,
I have made some changes in the way values are set in QuickForm elements.
Now, $_GET values won't override $_POST values from the form if the form
method is POST and the opposite is true as well.
This implied changes in the setDefaults and setConstants methods usage.
Use setDefaults to set default values for your elements. This default value
will be displayed in your form field the first time it is displayed, before
it is submitted. Then, if your form is displayed again because, let's say,
it has not been validated, $_POST or $_GET (submitted values) will override
the default value. This is logical.
Now, if you want to have the same value displayed all the time in a field,
even if the value has been changed by the user, you need to use setConstants
instead. So, if the form has not been validated, the displayed value will be
the constant one. But the submitted value is kept still in the _submitValues
array in case you need it.
To access these values, some accessor methods are available:
getSubmitValue will return the submitted value for one element or null if
its value has not been set yet.
getElementValue will return the element value such as set by using either
setConstant or setDefaults. Remember that if you used setDefaults, this
value will be overridden upon submit.
getSubmitValues will return the array of all submitted values, just like
$_POST or $_GET.
About groups:
I think groups need some improvements in their design, that's why I didn't
change the way they behave yet but it should be the same as for elements.
When I will have time to work on groups, I will try to implement the missing
features (group validation, groups in groups...). If you have any ideas
about that, please email me.
Thanks,
Bertrand Mansion
Mamasam
Here is a small test example. Use setConstants or setDefaults to see the
differences. Also, try to call this script by setting a GET variable:
test.php?var=20
<?php
require_once('HTML/QuickForm.php');
if (!isset($var)) {
echo '$var is unset<br>';
} else {
echo '$var Before: ' . $var . '<br>';
}
echo '$_GET[\'var\'] = ';
if (isset($_GET['var'])) {
echo $_GET['var'];
}
$form = new HTML_QuickForm('doc', 'POST');
//$form->setConstants(array('var' => '5'));
$form->setDefaults(array('var' => '5'));
$form->addElement('text', 'var');
$form->addElement('submit', 'submit', 'submit');
$form->toHtml();
$form->display();
echo $form->getElementValue('var');
echo '<br />';
echo $form->getSubmitValue('var');
?>