Creating Forms with Multiple Select Fields

From Contensive Wiki
Jump to: navigation, search

A multiple select form field is a select list that the user can hold down control and pick multiple items. They can be an alternative to checkboxes when the real estate on the select form is limited.

There is a issue with developing multiple select fields because different scripting platforms, on which Contensive runs, handle multiple select responses differently. As a result, Contensive has adopted a standard that works on either. The compromise is important so add-ons developed for php sites will still run on asp and aspx sites.

Creating the Form Field

The name of the field field should end with square brackets. For instance, if your multiple select field is a list of states:

<input multiple name="stateIdList[]">
<option value="1">New York</option>
<option value="2">California</option>
</select>

Processing the Response

To get the values from the field, be sure to include the square brakets in the field name

string stateIdList = cp.doc.getproperty( "stateidList[]" )

This returns a comma delimited list of values. The limitatiion here that you have to work around is that your option values should not contain a comma.