|
Using Form elementsWeb Form elements can be used in a Web Form or in a Capture OnTheGo Form (see Forms and Capture OnTheGo). This topic explains how to add these elements to a Form and how to prepare them so that when the Form is submitted, they provide valid data that can be handled easily. For a list of Form elements, see Form Elements. Adding elements to a FormTo add an element to a Form or Fieldset, click inside the Form or Fieldset, select Insert > Form elements, and choose the respective element on the menu. (When the element isn't available via the menu, see the tip below.) Now you can change the element's settings:
The name attribute of Form elements is sent to the server (together with the input value) after the form has been submitted. When adding an element to a Form or Fieldset, you cannot specify a Adding new HTML5 elementsHTML5 added several new input element types that can't be found in the Designer menu. To add such an element to a template you can do the following:
Changing a form elementOnce an element has been added to a Form, it can easily be changed: simply select the element in the template, go to the the Attributes pane, and edit the element. An input element can even be changed to another type of input element by selecting the desired input type from the Type drop-down list. Specifying a default valueAttribute a default value to a Text, Textarea and other Form elements by dragging a field from the Data Model pane directly onto the field, once it has been created. This also works when dragging a field from a detail table in a record set into a Form element that is contained within a Dynamic Table. Making elements requiredTo change the validation of a COTG or Form element, right-click the element and choose Validation settings. Now you can change the Form's validation method and set the requirements per field; see Changing a Form's validation method. Grouping data using arraysA Job Data File is an XML file created by a Workflow process upon submitting a Web Form or COTG Form. Grouping data in a Job Data File greatly simplifies both the Data Mapping workflow and looping over data in Designer scripts. A simple method to create arrays in that data file is to use two pairs of square brackets in the name of the form inputs. Put the name of the array between the first pair of square brackets. Between the second pair of square brackets, define the key to which the value belongs. Consider the following HTML form inputs:
The above HTML results in the following XML:
To enable submitting arrays, you need to check the Use PHP arrays option in the HTTP Server user preferences in Workflow; see Workflow Online Help.
In case multiple fields with the same name are encountered the previous value is overwritten. This way only a single occurrence of that field name will be available in the data containing the value of the last encountered occurrence of that field. This behaviour is also seen in the PHP language. You can try out this feature with the COTG Time Sheet template, as explained in this how-to: Using The PHP Array Option. The COTG Fields Table element (see Fields Table) in that template has an Add button to add rows to a table, and groups data following this approach. Getting the status of unchecked checkboxes and radio buttonsUnchecked checkboxes and radio buttons are not submitted (as per standard HTML behavior), so how to get the state of those checkboxes and radio buttons? A common approach to get the state of unchecked checkboxes and radio buttons is to add a hidden field to the Form with the same name as the checkbox or radio button, for example: <input type="hidden" name="status_1" value="0" /> <input type="checkbox" id="status_1" name="status_1" value="1" /> When multiple fields with the same name are encountered, the previous value is overwritten. This way the values for unchecked checkboxes and radio buttons can be processed easily. The Capture OnTheGo (COTG) plugin automatically adds a hidden field for every unchecked checkbox on a Form when the Form is submitted. It does this for every Form; the template doesn't have to be a COTG template. (See: Using the COTG plugin: cotg-2.0.0.js.)
|
|