PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #4010

Suppressing assigning submit value to elements in add-only forms

Details

Request #4010Suppressing assigning submit value to elements in add-only forms
Submitted2005-03-31 00:35 UTC
Frompaulw at projecthired dot org
StatusNo Feedback
PackageHTML_QuickForm
PHP Version4.3.3
OSLinux RH 9
Roadmaps(Not assigned)

Comments

[2005-03-31 00:35 UTC] paulw at projecthired dot org

Description:
------------
I have a form called 'Case Notes'. It consists of a date group that defaults to the current date, a textarea box, and submit/reset buttons.

Staff make journal entries into Case notes that are non-editable. The form is add-only, and after submitting, I need the textarea box to be set to blank.

However, when I make an entry, and press submit, the entry is in the textarea box after the page is refreshed. This means that staff will need to clean the box manually before typing in another entry.

Analysis of your code (QuickForm.php::onQuickFormEvent) shows that you have a pecking order for handling constants, defaults, etc. After an addElement or addGroup, if an element's initial value is 'null', and therea re no constants, nor default (or default is blank), you automatically assign the previously submitted value to it.

This is fine for standard forms, but will not work for Add-only forms. I am modifying my copy of Quickforms to do the following:
1) Add a new attribute to the form object describing this as 'add-only'.
2) In onQuickFormEvent, checking that the form is not 'add-only' before assigning submit value.

This might be the simplest way for you to handle this. I recommend that you analyze different classes of forms. My system has 4 different kinds:
1) Standard full-edit form
2) Search form
3) Add-Only
4) Batch (I will be implementing this soon - it's a form with a table of clients, each having a copy of a form. Very useful for large-scale data maintenance).

Of course, this would be a rather large job for you guys to implement, but in at least this one case, the type of form affects your code.

Reproduce code:
---------------
case 'updateValue':
// constant values override both default and submitted ones
// default values are overriden by submitted
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
$value = $this->_findValue($caller->_submitValues);

echo ":::Element::: Marker #1 name->".$this->_name." value->".$value."<br>";

if (null === $value) {
$value = $this->_findValue($caller->_defaultValues);
}
}
echo ":::Element::: Marker #2 name->".$this->_name." value->".$value."<br>";

Expected result:
----------------
:::Element::: Marker #1 name->
:::Element::: Marker #2 name->
:::Element::: Marker #3 name->

Actual result:
--------------
:::Element::: Marker #1 name-> value->entry #4
:::Element::: Marker #2 name-> value->entry #4
:::Element::: Marker #3 name-> value->entry #4

[2005-03-31 07:23 UTC] bmansion at mamasam dot com

Can't you just use setConstants(array('mytextarea' => '')) ?