Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nec massa tristique arcu ferme.

## 1. Create a Content Type with Public Submission Enabled

To accept forms from the public, you first must create a content type that will store the submissions.



Remove the data/customer_messages.yml, since you won't be pre-populating the content type with entries.



Now modify **app/content_types/customer_messages.yml** so it looks like this:



## 2. Create A Form

Now, you need to embed your form on a web page. Create the following page in **app/views/pages/contact.liquid**.



Lets go through it section by section...

This line sets up the form so its action goes to the Customer Messages content type's public submission url. Behind the scene, it generates a `<form>` HTML tag with the right parameters. It also generates a couple of hidden HTML fields storing the URLs for the callbacks (where the user is redirected on success or error) and the Cross-Site Request Forgery parameter which is needed if you turn on csrf protection (enabled by default).



Now on to error rendering. The most recently submitted content entry is stored in a variable that is the singular version of its Content Type's slug. For example, since we have a Customer Messages content type with a slug of customer_messages, the last submitted content entry is available as customer_message.

You can now loop through the errors attribute on customer_message and display those errors in the form. Error[0] is the field name and error[1] is the list of errors on that field.



The next section actually does the form submission. Data needs to be submitted by fields with the following naming convention: content[field_name]. Also, as noted above, the last submitted content entry is available as customer_message. This allows us to re-populate the form on error with `{{customer_message.field_name}}`.



Now all you need is a plain old submit button, and your form will allow users to send you messages through your website.



## Notes

You can also submit your forms using AJAX and something like jQuery Form. You will be able to detect success or failure via the HTTP status codes. Your errors or your newly created object will be returned to you as JSON. Below is an example of the error format:



To use the json API, you just need to let the `model_form` liquid tag know about it:



Thanks [Aaron](🔗) for submitting this guide!