Login / Survey online

Can anyone help me login with Mathematica to this site:

LetsFeedback.com is for sale | HugeDomains (?)

(here is a similar question of mine: Import with Login , in case anyone would be curious to have a look)

It would help me to centralize and analyze the data from several accounts..


Is it possible to create something similar (using e.g. FormFunction), store responses, analyse and display the results?

Thank you!

This should log you in to the site and store your session token as a cookie for future requests, although I can’t test it fully since I don’t have an account:

URLFetch["http://letsfeedback.com/presenter/login/login/", 
   "Method" -> "POST", 
   "Parameters" -> {"email" -> "jesse@example.com", 
     "password" -> "correcthorsebatterystaple"}];

An alternative method would be manually specifying your session token for each request.

It’s definitely possible to make a similar site using the Wolfram Programming Cloud. I don’t quite have time to make an example now, but here are some pointers:

  • Use a Data Drop databin for response storage. Make sure to set it to Private!
  • Make different cloud objects for each part of the app, like a FormFunction for data collection and an APIFunction returning a NotebookObject to display results.
  • If you anticipate a very large volume of responses, consider a scheduled task to do analysis on a periodic basis instead of on-the-fly.

This actually sounds like quite an interesting use case for the Programming Cloud. Good luck!

Thank you, Jesse!

It worked fine.. but, unfortunately I cannot access the data as it seems to be enclosed.


Now, I am interested to see what can I do in Mathematica.
To take it step by step, here is a form I have managed to create:

CloudDeploy[
 FormFunction[<|
   "Choice" -> <|
     "Interpreter" -> {"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4}, 
     "Control" -> RadioButtonBar|>|>, func, 
  AppearanceRules -> <|"Title" -> "Question 1.1", 
    "Description" -> 
     "If the supply curve for orange juice is estimated to be Q = 40 + 2p, then, at a price of p = 2, the price elasticity of supply is"|>]]

How do I add a new page (corresponding to another question) to this form?

You supply a list of associations instead of a single association as the first argument. However, it requires a bit of a hack to get different titles on each page. Here’s a function to make it easier:

pagesToFormspec[
  pages_List] := <|
    "Title" -> <|"Label" -> #[["Title"]], "Required" -> False, 
      "Hidden" -> True|>, 
    "Description" -> <|"Label" -> #[["Description"]], 
      "Required" -> False, "Hidden" -> True|>, 
    "Choice" -> #[["Choice"]]|> & /@ pages

questions = {<|"Title" -> "Question 1.1", 
   "Description" -> 
    "If the supply curve for orange juice is estimated to be Q = 40 + \
2p, then, at a price of p = 2, the price elasticity of supply is", 
   "Choice" -> <|
     "Interpreter" -> {"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4}, 
     "Control" -> RadioButtonBar|>|>, <|"Title" -> "Question 1.2", 
   "Description" -> "2+2 is", 
   "Choice" -> <|
     "Interpreter" -> {"A" -> 2, "B" -> 4, "C" -> 6, "D" -> 8}, 
     "Control" -> RadioButtonBar|>|>}

CloudDeploy[
 FormFunction[pagesToFormspec[questions], func, 
  FormLayoutFunction -> 
   Function[
    Grid[{{Annotation[
        Style[#["Title", "Label"], 
         "Section"], {"class" -> "form-title"}, 
        "HTMLAttrs"]}, {Annotation[Style[#["Description", "Label"], 
             "Text"], {"class" -> "form-description"}, 
        "HTMLAttrs"]}, {#["Choice"]}}, 
     Alignment -> Left]]], "formtest"]

Modify the questions variable to suit your needs. The association func is called with will contain “Title” and “Description” keys as well as the “Choice” key, but you can just ignore them.

Enjoy!

I just realized that code only returns a single “Choice” key in the response. Working on a fix.

Fixed it! New code below:

pagesToFormspec[pages_List] := 
 MapIndexed[<|
    "Title" -> <|"Label" -> #[["Title"]], "Required" -> False, 
      "Hidden" -> True|>, 
    "Description" -> <|"Label" -> #[["Description"]], 
      "Required" -> False, 
      "Hidden" -> True|>, {"page" <> 
       ToString[#2[[1]]], #[["Title"]]} -> #[["Choice"]], 
    "Page" -> <|"Label" -> ToString[#2[[1]]], "Required" -> False, 
      "Hidden" -> True|>|> &, pages]

questions = {<|"Title" -> "Question 1.1", 
   "Description" -> 
    "If the supply curve for orange juice is estimated to be Q = 40 + \
2p, then, at a price of p = 2, the price elasticity of supply is", 
   "Choice" -> <|
     "Interpreter" -> {"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4}, 
     "Control" -> RadioButtonBar|>|>, <|"Title" -> "Question 1.2", 
   "Description" -> "2+2 is", 
   "Choice" -> <|
     "Interpreter" -> {"A" -> 2, "B" -> 4, "C" -> 6, "D" -> 8}, 
     "Control" -> RadioButtonBar|>|>}

CloudDeploy[
 FormFunction[pagesToFormspec[questions], func, FormLayoutFunction ->
     (Grid[{{Annotation[
         Style[#["Title", "Label"], 
          "Section"], {"class" -> "form-title"}, 
                "HTMLAttrs"]}, {Annotation[
         Style[#["Description", "Label"], "Text"], 
                {"class" -> "form-description"}, "HTMLAttrs"]}, {#[
         "page" <> #["Page", "Label"][[1]]]}}, 
          Alignment -> Left] & )], "formtest"]

That’s really great. Thank you.

Is it possible to add a “Back” button and also to display the choices in a column?
All my attempts to do that ended in failure.

For a vertical radio button column, replace RadioButtonBar under Control in each question association with Function[RadioButtonBar[##, Appearance -> "Vertical"]]. If all of your questions are multiple-choice, you could also simplify the questions variable so it could just be "Choice"->{"A"->1,"B"->2,"C"->3,"D"->4}.

I don’t think it’s possible to add a back button, at least not with a plain FormFunction. You could make a custom HTML interface talking to an Instant API instead, but that might be a bit overkill.