FormFunction
This feature relies on access to Wolfram Cloud.

FormFunction[formspec,func]
represents an active form that, when submitted, applies func to the values obtained from the form specified by formspec.

FormFunction[{"name1"type1,},func]
represents an active form with fields named interpreted as types .

FormFunction[{{"name1",label1}type1,},func]
uses as the label for the field named .

FormFunction[{namespec1type1default1,},func]
uses as the default for the field specified by .

FormFunction[formspec,func,fmt]
specifies that in the cloud the result from applying func should be returned in format fmt.

FormFunction[{formspec1,formspec2,},func,]
represents a multipage form, in which the successive can be functions that are applied to the values obtained so far.

Details and OptionsDetails and Options

  • FormFunction[formspec,func] displays the form specified by formspec, together with a "submit" button.
  • FormFunction[formspec,func] evaluates to give FormFunction[FormObject[],func], where the FormObject contains full specifications for all fields in the form.
  • CloudDeploy[FormFunction[]] yields a cloud object containing an active version of the form.
  • FormFunction[formspec,func][] evaluates by first evaluating Setting[formspec] to give an association of values for fields in the form. If no validation errors are generated, func is applied to the association, and the result is returned.
  • FormFunction[formspec,func][<|"namek"->inputk,|>] inserts the inputs given into the form specified by FormFunction before evaluating the effect of the FormFunction.
  • FormFunction[][] evaluates to an active form, which, assuming it has valid input given, is replaced by the result from applying func when it is submitted.
  • FormFunction[][assoc] effectively inserts inputs before applying func.
  • Overall options for FormFunction include:
  • AppearanceRulesAutomaticassociation giving overall appearance rules
    FormLayoutFunctionAutomaticfunction to generate layout for the form
    FormThemeAutomaticoverall theme to use for the form
    ImageFormattingWidth$ImageFormattingWidthwrapping width for output formatting
    ImageSizeAutomaticoverall image size for output
  • When called in the cloud, FormFunction[formspec,func] by default returns the result in a format suitable for web output.
  • Possible result specifications fmt in FormFunction[formspec,func,fmt] are:
  • Automaticexport in a format suitable for web output (default)
    "HTML"export as complete static HTML page
    "CloudCDF"export as CloudCDF with interactive components in the cloud
    "HTMLCloudCDF"export as HTML with CloudCDF if needed
    "GIF","JPEG","PNG",image of the result
    "String"raw string form of the result
    "fmt"any format supported by ExportForm
    Nonepass a string or list of bytes through without change
    {None,"type"}pass through, with a specific HTTP response type defined
    {fmt,opts}format specification with options
    fan arbitrary function to be applied to body
  • When called in the cloud, FormFunction[formspec,func,"fmt"] is equivalent to FormFunction[formspec,ExportForm[func[#],"fmt"]&].
  • When called directly in the notebook interface, the result specification fmt in FormFunction[formspec,func,fmt] is ignored.
  • In multipage forms represented by FormFunction[{formspec1,formspec2,},], the successive forms specified by the are displayed, with the last form by default having a "done" button, and earlier forms by default having "next" buttons.
  • In FormFunction[{formspec1,formspec2,},], the after are typically always pure functions. They are applied to an association giving the values of all inputs obtained from all earlier .

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

Set up a form function:

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

Activate it, then fill in inputs:

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

Deploy the form function to the cloud:

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

Programmatically fill in the form:

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

A partially submitted form will not be activated:

In[5]:=
Click for copyable input
Out[5]=
Introduced in 2014
(10.0)