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 assoc an association as used in FormObject tfun any 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 Automatic association giving overall appearance rules FormLayoutFunction Automatic function to generate layout for the form FormProtectionMethod Automatic method for spam protection ImageFormattingWidth $ImageFormattingWidth wrapping width for output formatting ImageSize Automatic overall image size for output PageTheme Automatic overall 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:
-
Automatic export 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 None pass 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 f an 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 allBasic Examples (2)
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:
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:
Label (1)
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:
Change the appearance of single fields:
Use RuleDelayed to evaluate an expression in the cloud:
Controls (7)
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)
Properties & Relations (8)
FormFunction is designed to be interchangeable with APIFunction:
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:
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