Skip to main content
2 of 5
added 1991 characters in body
M.R.
  • 31.8k
  • 8
  • 96
  • 289

How to deploy a simple contact form with WebItems?

I'd like to make a contact form exactly like this page:

enter image description here

Of course changing the icon and where it gets sent to, but otherwise exactly the same look.

There must be a 'hello world' example with email address validations and multiple input fields that I'm missing.... It should be easy to format this with the new WebItem, WebColumn, WebRow symbols in v13 right?

CloudDeploy@
 WebColumn[{WebItem[Rasterize["My Icon"], {200}], 
   WebItem["Please leave a detailed comment in the space below:"], 
   FormControl[Dynamic[message], 
    FormObject[{"message", 
       "Please leave a detailed comment in the space below:"} -> 
      "String"]], 
   FormControl[Dynamic[address], 
    FormObject[{"email", "Email:*"} -> "String", 
     AppearanceRules -> <|"ItemLayout" -> "Vertical"|>]], 
   WebItem["Attachment:"], 
   WebRow[{WebItem[Checkbox[]], WebItem["I agree..."]}], 
   WebItem@
    Button["Submit", SendMail[address, message], Background -> Red]}, 
  Alignment -> Center]

Response

The first piece of code makes the form page as you show, but I don't see a "send to" address, it doesn't send results to my wolfram cloud email account either...

banner = URLExecute@"https://picsum.photos/300/150";
CloudDeploy[ (*where is the "to" email address?*)
 FormFunction[{"Name" -> <|"Interpreter" -> "String", "Label" -> None|>,
    "Email" -> <|"Interpreter" -> "EmailAddress", "Label" -> None|>, 
   "Message" -> <|"Interpreter" -> "TextArea", 
     "Hint" -> "Please leave a more detailed comment", 
     "Label" -> None|>, 
   "Agreed" -> <|"Interpreter" -> "Boolean", 
     "Label" -> "I agree to the resale of my data on the dark web"|>},
   TemplateApply[
    "Thanks ``! Your submission went through.", {#Name}] &, 
  FormLayoutFunction -> 
   With[{r = banner}, 
    Function[
     Column[{Item[r, Alignment -> Left], "Name", #["Name", "Control"],
        "Email", #["Email", "Control"], 
       Spacer[{10, 5}], #["Message", "Control"], 
       Row@{#["Agreed", "Control"], 
         Spacer[10], #["Agreed", "Label"]}}, 
      Alignment -> Left]]]], "testControl", Permissions -> "Public"]

Please excuse my nitpicking, but there are a few more tiny discrepancies:

  • There is no drag and drop field.
  • The email and name fields are not enforced (you can click submit without filling them out and the page reloads but doesn't highlight the incomplete fields)
  • The background isn't white (and there's an extra Panel[] it looks like)
  • The spacing and fonts are off (probably easy to fix this one)
  • The gray bar at the bottom "made with wolfram" shouldn't be there... (I'm guessing that impossible to remove?)

enter image description here

The second piece of code (the fully-fleshed-out snippet) spews errors for me in desktop version 13.0 (and there are no controls in the generated page):

enter image description here

M.R.
  • 31.8k
  • 8
  • 96
  • 289