Forms & Actions > Forms - Recipient management > Forms > Advanced form layout > Creating a HTML form dynamically

Creating a HTML form dynamically

When creating a recipient profile from data entered into a form, there are certain types of data where an entry field is not the best way of processing entries. Drop-down lists are more suitable for data with a limited number of selections like gender, while a check box is ideal for opting in or out of a mailing list.

The previous chapter explained how to create a drop-down list within an entry form. When returning data from an existing profile, however, the correct option from the drop-down list must be selected. To do this, the selected attribute must be inserted against that selection’s <option> tag within the HTML code. Selecting an option using a check box is done in a similar way: the checked attribute returns a check. Script commands will insert the attributes where required and depending on the subscriber profile. Our example for displaying the mail format from a drop-down list looks like this:

Mail-Format: <select name="MAILTYPE" size="1">
Text
</option>
<option value="1" #if( $customerData.MAILTYPE == "1" ) selected #end >
HTML
</option>
<option value="2" #if( $customerData.MAILTYPE == "2" ) selected #end >
Offline-HTML
</option>
</select><br>

The list option selected in the browser window must have the selected attribute against its value. First, the #if query checks whether or not the value stored in the database is plausible for the list option concerned. The $customerData.MAILTYPE code calls up the value stored in the profile. MAILTYPE is the name of the field where OpenEMM stores the mail type selected by the recipient. If the value selected and the value found are identical, the script command inserts the text from the ‘if’ query immediately before #end into the HTML code. For instance,

<option value="2" #if( $customerData.MAILTYPE == "2" ) selected #end >

will return

<option value="2" selected >

if the recipient profile has a mail type of 2. If the value is not 2 but 1 or 0, the following HTML tag is created instead:

<option value="2">

Only the <option> tag whose value corresponds to the entry in the recipient profile will therefore be selected.