FormFunction

Listing of Field Types »

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 namei interpreted as types typei.

FormFunction[{{"name1",label1}type1,},func]

uses labeli as the label for the field named namei.

FormFunction[{namespec1type1default1,},func]

uses defaulti as the default for the field specified by namespeci.

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 formspeci can be functions that are applied to the values obtained so far.

Details and Options

  • FormFunction[formspec,func] displays the form specified by formspec, together with a "submit" button.
  • In FormFunction[formspec,func], formspec can be FormObject[].
  • 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.
  • The typei for each field can be any of the following:
  • "form"any form supported by Interpreter
    Restricted[], etc.any restricted form etc. supported by Interpreter
    Interpreter[]any Interpreter object
    assocan association as used in FormObject
    tfunany function to be applied to the string
  • In multipage forms represented by FormFunction[{formspec1,formspec2,},], the successive forms specified by the formspeci 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 formspeci after formspec1 are typically always pure functions. They are applied to an association giving the values of all inputs obtained from all earlier formspeci.
  • Overall options for FormFunction include:
  • AppearanceRules Automaticassociation giving overall appearance rules
    FormLayoutFunction Automaticfunction to generate layout for the form
    FormProtectionMethodAutomaticmethod for spam protection
    ImageFormattingWidth$ImageFormattingWidthwrapping width for output formatting
    ImageSizeAutomaticoverall image size for output
    PageTheme Automaticoverall theme to use for the deployed web page
  • 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 as HTML or CloudCDFElement as appropriate
    "HTML"export as raw static HTML page without dynamic content
    "HTMLThemed"export as static HTML using the same theme as the form
    "HTMLPaneled"export as HTML content in a panel
    "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.

Examples

open allclose all

Basic Examples  (2)

Set up a form function:

Activate it, then fill in inputs:

Deploy the form function to the cloud:

Programmatically fill in the form:

A partially submitted form will not be activated:

Create dynamic forms:

Scope  (25)

Interpreter Specifications  (6)

Use rich Interpreter specifications:

The Interpreter head is optional, but useful to specify options or other arguments to Interpreter:

A list can be used to create a menu:

An entity list can be used as a menu:

Choices can be any expression:

A list of rules allows for label specification:

Defaults  (3)

Specify a default for a field; fields that have a default are not required:

Fields can be optional without having a default:

Use RuleDelayed to evaluate a new default every time:

Input  (2)

Create a form with input inside:

Input can be delayed:

Label  (1)

Change the label for a field:

You can use RuleDelayed and return any expression:

Use None to remove the label:

Appearance  (4)

Change the default label to be something different from the key:

Labels can be any expression:

Change the appearance of single fields:

Use RuleDelayed to evaluate an expression in the cloud:

Use non-rule elements to change the default appearance:

Controls  (7)

Different types have different controllers. Color pickers for "Color":

Or file pickers for file formats:

Checkboxes for "Boolean":

Change the default controller:

Multiple choices support various types of controllers:

Labels for radio buttons can be anything you want:

The control specification also accepts pure functions:

Dynamic forms  (1)

Parts of forms that contain TemplateSlot are not evaluated until the keys mentioned in TemplateSlot[key] are bound to a proper value:

Multipage forms  (1)

FormFunction supports forms that span several pages. The fields depend on values in previous pages:

Options  (6)

AppearanceRules  (1)

Write a custom title and description:

Use an image for branding:

Use an "ItemLayout" to change form fields' appearance:

Change the submit label:

FormLayoutFunction  (1)

A pure function can be specified to give a specific layout to a form:

PageTheme  (4)

Deploy a form with a white theme:

Deploy a form with a blue theme:

Deploy a form with a black theme:

Deploy a form with a red theme:

Applications  (2)

Draw the flight path between two airports:

Get demographic data for a city:

Properties & Relations  (8)

FormFunction is designed to be interchangeable with APIFunction:

And vice versa:

The first argument of FormFunction can be given as a full FormObject:

FormFunction evaluates so that the first argument becomes a full FormObject:

The single fields of a FormFunction use Interpreter to transform the input in Wolfram Language expressions:

This is effectively the same as:

And the same as applying Interpreter directly:

AnySubset can be used to generate a controller where more than one choice can be picked:

RepeatingElement can be used to create a group of fields that can be added and deleted:

CompoundElement can be used to create an extensible table of fields:

Possible Issues  (1)

Interpreter["String"] accepts an empty string. This is not true for FormFunction, where the empty string and an empty field are considered equivalent:

Neat Examples  (3)

Create a search engine that redirects to a URL:

Make a simple web application to apply a filter to an image:

Output audio:

Open the form page, type a message and click the "Submit" button:

Click the play button to hear your message:

Wolfram Research (2014), FormFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/FormFunction.html (updated 2015).

Text

Wolfram Research (2014), FormFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/FormFunction.html (updated 2015).

CMS

Wolfram Language. 2014. "FormFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/FormFunction.html.

APA

Wolfram Language. (2014). FormFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FormFunction.html

BibTeX

@misc{reference.wolfram_2023_formfunction, author="Wolfram Research", title="{FormFunction}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/FormFunction.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_formfunction, organization={Wolfram Research}, title={FormFunction}, year={2015}, url={https://reference.wolfram.com/language/ref/FormFunction.html}, note=[Accessed: 19-March-2024 ]}