Jump to main content Jump to doc navigation

Here we will give a simple example of Contact page.

We presume that you have already installed Formit component via Package Management and got acquainted Formit How To Use section.

This example Contact form will validate input data, send an email and finally redirect to Resource with ID 123.

Validation process (see how it works here, in short - each hook executes some kind of logic, if successful - transfers processing to the next hook ) in this example does the following: also strip tags from the message, validate the email as a real email address, and make sure none of the fields are blank. All this is specified in &validate parameter.

And finally, we want reCaptcha support. We've already setup our public and private keys for reCaptcha via the following System Settings:

  • formit.recaptcha_public_key
  • formit.recaptcha_private_key

Snippet Tag

You can call this snippet anywhere: inside template, chunk, page content body, or even call programmatically via runSnippet.

There is only one condition - Formit must be launched on the page where data from Contact form below will be sent (see "action" field value).


Please make sure that emailFrom is set to [[++emailsender]], otherwise the email field of the form will be taken. This is now causing issues as most hosters no longer send mails with a from from unknown domains.

Contact Form

This HTML code must be called on website page where you want to see Contact Form. "Action" field value points to the page where the snippet call is located, in our case we call it on the same page, so we use ~ tag to generate a link for the current page.

<h2>Contact Form</h2>


<form action="[[~[[*id]]]]" method="post" class="form">
    <input type="hidden" name="nospam" value="" />

    <label for="name">
        <span class="error">[[!+fi.error.name]]</span>
    <input type="text" name="name" id="name" value="[[!+fi.name]]" />

    <label for="email">
        <span class="error">[[!+fi.error.email]]</span>
    <input type="text" name="email" id="email" value="[[!+fi.email]]" />

    <label for="subject">
        <span class="error">[[!+fi.error.subject]]</span>
    <input type="text" name="subject" id="subject" value="[[!+fi.subject]]" />

    <label for="text">
        <span class="error">[[!+fi.error.text]]</span>
    <textarea name="text" id="text" cols="55" rows="7" value="[[!+fi.text]]">[[!+fi.text]]</textarea>

        <select name="numbers" value="[[!+fi.numbers]]">
            <option value="">Select an option...</option>
            <option value="one" [[!+fi.numbers:FormItIsSelected=`one`]]>One</option>
            <option value="two" [[!+fi.numbers:FormItIsSelected=`two`]]>Two</option>
            <option value="three" [[!+fi.numbers:FormItIsSelected=`three`]]>Three</option>

        <input type="hidden" name="colors[]" value="" />
        <label><input type="checkbox" name="colors[]" value="red" [[!+fi.colors:FormItIsChecked=`red`]] /> Red</label>
        <label><input type="checkbox" name="colors[]" value="blue" [[!+fi.colors:FormItIsChecked=`blue`]] /> Blue</label>
        <label><input type="checkbox" name="colors[]" value="green" [[!+fi.colors:FormItIsChecked=`green`]] /> Green</label>

    <br class="clear" />

    <br class="clear" />

    <div class="form-buttons">
        <input type="submit" value="Send Contact Inquiry" />

MyEmailChunk (Tpl Chunk)

Below is email chunk(from &emailTpl) that we send to specified in &emailTo Formit parameter after form data receipt and validation.

This is the Formit Email Chunk.

<br />[[+name]] ([[+email]]) Wrote: <br />


See Also

  1. AjaxForm Submit any form via Ajax (FormIt wrapper extra)
  2. FormItAutoResponder
  3. What is Google Recaptcha
  4. ReCaptchaV2 Google Recaptcha(V2 and V3 supported) extra for MODX