Creating A Hidden Field
Creating A Hidden Field
Named parameter style
print
$query->hidden(-name=>'hidden_name',
-default=>['value1','value2'...]);
Old style
print
$query->hidden('hidden_name','value1','value2'...);
hidden() produces a text field that can't be seen
by the user. It is useful for passing state variable information from one
invocation of the script to the next.
- The first argument (-name) is required and
specifies the name of this field.
- The second and subsequent arguments specify the value for
the hidden field. This is a quick and dirty way of passing perl arrays through
forms. If you use the named parameter style, you must provide the parameter
-default and an array reference here.
As of version 2.0 I have changed the
behavior of hidden fields once again. Read this if you use hidden fields.
Hidden fields used to behave differently from all other
fields: the provided default values always overrode the "sticky" values. This
was the behavior people seemed to expect, however it turns out to make it harder
to write state-maintaining forms such as shopping cart programs. Therefore I
have made the behavior consistent with other fields.
Just like all the other form elements, the value of a
hidden field is "sticky". If you want to replace a hidden field with some other
values after the script has been called once you'll have to do it manually
before writing out the form element:
$query->param('hidden_name','new','values','here');
print
$query->hidden('hidden_name');
Fetch the value of a hidden field this way:
$hidden_value =
$query->param('hidden_name');
-or (for values created with
arrays)-
@hidden_values =
$query->param('hidden_name');
|