Form Processor
Description:
The FormProcessor snippet will process almost any HTML form. The submitted data can be emailed or saved to a database (there is currently no simple method to view data that is saved in the database but it should be coming soon).
Requirements:
MODx CMS 0.9.1
Download:
FormProcessor snippet
- Download the FormProcessor snippet
- Create a new snippet by clicking the New Snippet link in the Snippets tab of the Manage Resources page.
- Copy the contents of the textfile into a new snippet and copy the Name, Description and Properties from the comments at the top of the file into their appropriate fields.
- Save the snippet.
- If you don't want to save submissions to the database, go to the Properties tab and set Write Data to Database to 0 and you're done. Otherwise, read on.
- If you would like to save submissions to the database you will have to make sure that the database user that MODx is using has CREATE TABLE rights in the MODx database. The appropriate tables will be automatically created the first time you submit a form.
After submitting your first form, check the Event Logs page. If you don't see any errors from the FormProcessor snippet then the tables have been created successfully and you're done.
If you do see error, you'll either have to grant CREATE TABLE rights to the user or run the SQL given in the error details manually.
Usage (Snippet):
The FormProcessor snippet must be called from within the content of a document, like so
[!FormProcessor? &form_chunk=`ExampleForm` &data_email_address=`your_email@your_domain.com` &form_required=`Name,Message`!](Replace value names in backticks with corresponding values. form_name is required)
[ExampleForm] is the name of the chunk that contains the HTML for the form. [your_email@your_domain.com] is the email address where you want the form submissions sent. [Name,Message] is a comma-separated list of form input names for required fields.
Usage (ExampleForm Chunk):To create a form to use with the FormProcessor you'll have to put the HTML for the form in a new chunk. An example form is provided below
<form action="[~[*id*]~]" method="post"> <input type="hidden" name="send_to" value="FormProcessor" /> <div> <label>Your Name</label> [+Name-required_message+]<br /> <input type="text" class="[+Name-required_class+]" name="Name" value="[+Name-value+]" /> </div> <div> <label>Your Choice</label><br /> <select name="Choice"> <option [+Choice-selected-door_1+]>Door #1</option> <option [+Choice-selected-door_2+]>Door #2</option> </select> </div> <div> <label>Your Message</label> [+Message-required_message+]<br /> <textarea class="[+Message-required_class+]" name="Message">[+Message-value+]</textarea> </div> <div> <button type="submit">Send</button> </div> </form>There are five types of placeholders that are registered when a form is submitted but all required fields were not filled.
- [+Input_Name-value+] contains the submitted value of the input.
- [+Input_Name-checked-Checkbox_value+] Contains checked="checked" for checkbox and radio inputs that were checked.
- [+Input_Name-selected-List_value+] Contains selected="selected" for option inputs that were selected.
- [+Input_Name-required_message+] Contains a "Missing Input Name" type message for required inputs that are missing values.
- [+Input_Name-required_class+] Contains a class for use in a class tag for required inputs that are missing values.
Any form you want processed by the form_processor will have to have a hidden input with the name send_to and the value FormProcessor, other wise the submission will be ignored by the snippet.
Names that are given to <input> tags should have underscores (_) in the place of spaces. Spaces will be substituted for underscores before the names are stored in the database or sent in an email.
The checked and selected placeholders contain the value of the option tag after the last dash. To reference these values in a placeholder you'll need to replace spaces with underscores (_) and remove anything that is not a letter, number or underscore.
Example:
Support:
If you have any questions, problems or feature requests, please search the MODx forums as your request may have already been addressed there. If you did not find what you were looking for in the forms you can post a new topic there or contact me directly.