Building a contact form, step by step
This page is for website creators who need a working contact form. It uses the information collector
(Forms with the information collector). If your site package ships the
Feedback form class (feedback_form), steps 1 and 2 are already done; start at step 3.
Steps
1. The class. In Setup > Classes > Content > New class: name Contact form, identifier contact_form,
container off. Attributes:
| Name | Identifier | Datatype | Required | Information collector |
|---|---|---|---|---|
| Title | title | Text line | yes | no |
| Introduction | description | Rich text | no | no |
| Your name | sender_name | Text line | yes | yes |
| Your e-mail | email | yes | yes | |
| Message | message | Text block | yes | yes |
Object name pattern: <title>.
2. Spam protection. Add a reCAPTCHA or hCaptcha attribute when one of those extensions is active (Spam protection for forms).
3. The form object. Create a Contact form called "Contact" under the root folder, write an introduction, publish.
4. The template. Copy the shipped feedback form template into your design as
override/templates/full/contact_form.tpl, rename the fields to your identifiers, and add the override rule:
# settings/siteaccess/<site>/override.ini.append.php
[full_contact_form]
Source=node/view/full.tpl
MatchFile=full/contact_form.tpl
Subdir=templates
Match[class_identifier]=contact_formGive every input a visible <label>; mark required fields in text, not only by color.
5. Mail. Set the receiver:
# settings/siteaccess/<site>/site.ini.append.php
[InformationCollectionSettings]
EmailReceiver=[email protected]and override content/collectedinfomail/form.tpl if the mail should look different.
6. Thank-you page. Create a page "Thank you" and redirect to it:
# settings/siteaccess/<site>/collect.ini.append.php
[DisplaySettings]
Display=redirect
RedirectURL=/Thank-you7. Visitors may send. Anonymous needs content/read on the form (Section Standard is enough) and the
content/collectinformation view uses the read function, so nothing else is needed. Leave
CollectAnonymousData=enabled.
8. Caches. php bin/php/ezcache.php --clear-id=template-override --allow-root-user, then --clear-tag=template
and --clear-tag=content.
9. Test, logged out. Send the form with an empty required field (an error message appears beside it), then correctly (the thank-you page appears). With the file mail transport, check the mail in the mail directory.
10. Check the submission in Setup > Collected information: the Contact object has one collection.
Checklist
- To do: Every input has a label; errors are announced next to the field.
- To do: Spam protection is on.
- To do: The privacy note says what happens with the data.
- To do: Mail arrives at the team address (with real mail switched on).
- To do: Reloading the thank-you page does not resend.
Related pages
- Forms with the information collector
- Reading and exporting form submissions
- Template overrides for site builders
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.