how to autopopulate email address with modx FormIt form from a url

514 Views Asked by At

I have a website that was done in Modx(yuck) and using FormIt I created a simple page with 1 field, an email textbox.

   <form method="post" action="" id="1">
   <label for="advisorName">Email Address:</label><input id="email" type="text" name="email" value=""></form>

How can I get the email field populated from an url like:

www.example.com/unsubscribe.html?id=1&[email protected]

This is easy for me with a standard website, but I am so lost with Modx.

2

There are 2 best solutions below

2
On BEST ANSWER

You want to create a "Snippet", which is just a piece of php code. Call your snippet whatever and something like this should do:

return (!empty($_GET['email']) ? $_GET['email'] : 'Enter e-mail');

Then in your chunk/template or wherever that code you pasted is, change the input value to: value="[[!NameOfYourSnippet]]". The bracers indicate that it's a snippet you want to call and the exclamation mark tells modx not to cache whatever is rendered by it.

Happy modx:ing!

1
On

Read the docs - http://rtfm.modx.com/extras/revo/formit/formit.hooks/formit.hooks.email

[[!FormIt?
   &emailTo=`[[+addressTo]]`
]]
...
<select name="addressTo">
   <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>John</option>
   <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Jane</option>
</select>

or if you just need to get email field - http://rtfm.modx.com/extras/revo/formit/formit.tutorials-and-examples/formit.examples.custom-hook