Message Boards Message Boards

4 Replies
5 Total Likes
View groups...
Share this post:

Need examples of multipage FormFunction[]

Dear community, FormFunction has a multipage option FormFunction[{formspec1,formspec2,…},func,…]. I wonder if it is possible to use values from formspec1 to preset the values of formspec2? Any example would be very much appreciated.

POSTED BY: Truly Unique
4 Replies

Thank you, Chad! This does answer my question.

POSTED BY: Truly Unique

My apologies. I didn't read the documentation carefully enough. Note that it says that forms are pure functions that are applied to an association of previous input. So just define the subsequent forms explicitly as pure functions.

Here are some simple examples:

FormFunction[{{"x" -> "Number"}, {"y" -> {#x , 2, 3} } &}, {#x, #y} &][]


FormFunction[{{"x" -> {"cat", "actress"}}, {Switch[#x, "cat", 
     "y" -> "CatBreed", "actress", 
     "y" -> {Entity["Person", "AnneHathaway::fkdf7"], 
       Entity["Person", "HalleBerry::hj23z"], 
       Entity["Person", "LeeMeriwether::863fn"]}]} &}, #y["Image"] &, "PNG"]
POSTED BY: Chad Knutson

Thank you, Chad! I would still like to explore the multipage FormFunction[] options to get a "clean" solution. The Wolfram Programming Cloud documentation says:

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

I wonder if you could give me an example, illustrating the above statement.

Thanks in advance, Stas

POSTED BY: Truly Unique

Stas, apologies for the slow response. I was trying to think of ways that this can be done, but I don't think it is possible. UPDATE: Very possible. See my reply below.

An alternative solution would be to use separate FormFunctions. but this is not nearly as "clean". Here is a trivial example.

a2 = CloudDeploy[ FormFunction[{"x" -> {"cat", "person"}}, 
   Switch[#x, "cat", HTTPRedirect[First@cat], "person", HTTPRedirect[First@person]] &]]

Where I have previously defined (and deployed) the secondary forms:

cat = CloudDeploy[FormFunction[{"x" -> "CatBreed"}, #x["Image"] &, "PNG"]]


person = CloudDeploy[FormFunction[{"person" -> "Person"}, #person["BirthDate"] &]]
POSTED BY: Chad Knutson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract