Wolfram Language & System 10.3 (2015)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)
WOLFRAM LANGUAGE TUTORIAL

Advanced Web Form Creation

Though FormFunction and FormObject provide a very terse interface for creating simple web forms, this tutorial will cover the methods and options necessary for the creation of more advanced web forms.

Appearance Rules

FormFunction and FormObject take the option AppearanceRules, which can be used to specify various parts of the form, such as the title and the way the elements are displayed in each field.

Title and Description

You can use AppearanceRules with and to add a title and a subtitle to your form.

In[5]:=
Click for copyable input
Out[5]=

SubmitLabel and NextLabel

You can use to change the text displayed in the button at the bottom of the form.

In[8]:=
Click for copyable input
Out[8]=

Similarly, can be used to customize the text in all the fields except for the last in a multipage form.

Non-textual Values

Most of the fields in AppearanceRules do not need to be strings.

In[12]:=
Click for copyable input
Out[12]=

RequiredFieldIndicator

applies a function to the labels of the required fields.

In[13]:=
Click for copyable input
Out[13]=

ItemLayout

can be used to decide the way the elements are displayed in a grid. Empty rows and columns are automatically elided.

The default corresponds to a 2×2 grid.

In[19]:=
Click for copyable input
Out[19]=

corresponds to all the elements laid out on the same row.

In[21]:=
Click for copyable input
Out[21]=

corresponds to all the elements laid out on the same column.

In[22]:=
Click for copyable input
Out[22]=

Multipage Forms

Forms can span multiple pages; an additional list in the first argument specifies a multipage form.

In[23]:=
Click for copyable input
Out[23]=

All pages except the first can be specified as pure functions; doing so will let you have new pages that depend on the old ones.

In[24]:=
Click for copyable input
Out[24]=

You can use this technique to create new fields programmatically.

In[26]:=
Click for copyable input
Out[26]=

Note that fields in different pages can have the same key. If this happens, the newest value will overwrite the old.

Dynamic Forms

Sometimes it is useful to define a form where one field depends on another and where both appear on the same page. This can be done by using the Wolfram Language templating language, with symbols such as TemplateSlot.

In[59]:=
Click for copyable input
Out[59]=

Fields that depend on other fields are automatically hidden until there is enough information to display them, while fields that have other fields depending on them automatically submit when filled in.

Autosubmitting

You can force a field to automatically submit the whole form when it is filled in by wrapping it with AutoSubmitting.

In[60]:=
Click for copyable input
Out[60]=

Note that when selecting the second field after typing in the first, the whole form is submitted, resulting in a failure message below the second field.

RepeatingElement and CompoundElement

Sometimes it is useful to have a variable number of fields in a form. Use RepeatingElement to repeat a field.

In[1]:=
Click for copyable input
Out[1]=

Using the second argument of RepeatingElement, you can make a subfield depend on its index.

In[2]:=
Click for copyable input
Out[2]=

CompoundElement can be used with RepeatingElement to create a table of fields.

In[6]:=
Click for copyable input
Out[6]=

The AppearanceRules options and can be used to customize the labels of the buttons in a RepeatingElement.

In[65]:=
Click for copyable input
Out[65]=