FORMfields, the premiere web framework
Login
Support Home | Knowledge Base | Documentation | Forums | Contact Us
Info
FORMfields & FORMgen :: Field Customizations

Using a Hidden Field to Store External Data With Your Form

(2365 views. Last Updated: 2007-08-13 2:00 PM)

Here are examples of how to use a HiddenField to store data in your form.

Example 1: Set the value in FORMgen. In this example we will assume the value is "732"
1. Use FORMgen to generate a form and add a HiddenField:
Name: my_data
Value: 732
Max Length: 10
2. When the user submits the form, a value of "732" will be stored in my_data.

Example 2: Pass the value of the HiddenField in the query string:
1. Use FORMgen to generate a form and add a HiddenField:
Name: my_data
Value: No Value
Max Length: 10
2. Test out the form by visiting the form and passing in the value of my_data: http://www.mysite.com/FORMfields/forms/generated/my_form.php?my_data=454. When the user submits this form, a value of "454" will be stored in my_data.

Example 3: Set the value of the HiddenField using PHP:
1. Use FORMgen to generate a form and add a HiddenField:
Name: my_data
Value: No Value
Max Length: 10
2. Edit your form and replace:
$ffForm->loadDbValues($GLOBALS["FF_DEFAULTS"]);
// Enter other default values here. Example: 
//$ffForm->setValue("name", "John");
with something like:
$ffForm->loadDbValues($GLOBALS["FF_DEFAULTS"]);
// Enter other default values here. Example: 
$myData = "2344";
$ffForm->setValue("my_data", $myData);
When the user submits this form, a value of "2344" will be stored in my_data.

Optional: You can modify your Control Panel so that you can edit the value of the HiddenField:
To do this, replace:
$ffForm->addField(new HiddenField("my_data", "No Value", 10, null));
with:
//$ffForm->addField(new HiddenField("my_data", "No Value", 10, null));
$ffForm->addField(new TextField("my_data", "My Data", FORM_FIELD_REQUIRED, 10, 1, null));
Info
Support | Earn Money
Copyright © 2005-2019 Brain Book Software LLC.
Built with FORMfields, the premiere web framework.