How to make field required/not-required in a RD mail-form

This guide will help you to make a field required or non-required in an RD Mailform.

rd-mailform

As a rule, the contact form fields are required by default. In order to change this, you need to make the necessary edits to the form code. Firstly, you need to open the needed page (usually it is an index.html or contact.html file) in any code editor. Then you need to follow one of the possible ways, depending on the form type which is used in the template.

1. Templates based on RD Mailform

Let’s make the “Email” field non-required in order to illustrate the process.

  1. Locate the script which related to Email field, e.g.:
  2. You need to remove the @NotEmpty part in the data-constraints attribute.

After this, you will get the following code:

Then you just need to save the changes, re-upload the file to your server, refresh the page and test the form. You will see that the Email field is not required anymore.

To make any not required by default field required, just add @NotEmpty to the data-constraints attribute value of the corresponding form field. Make sure to separate the values with the space.

2. Templates based on forms.js script
  1. Locate the script which related to Email field, e.g.:
  2. Add the “notRequired” class after the “email” class:

Then save the changes, re-upload the file to your server, refresh the page and test the form. You will see that the Email field is not required anymore.

3. Templates based on TMForm.js script

Let’s make the “Name” field non-required in order to illustrate the process.

  1. Locate the script which is related to the Name field, e.g.:
  2. Remove the “@Required” from the data-constraints attribute list. The edited code will look like:

Save the changes, re-upload the file to your server, refresh the page and test the form. You will see that the Name field is not required anymore.

To make a field required, just add @Required to the data-constraints attribute value of the corresponding form field. Make sure to separate the values with the space.

Now you know how to make the field required/non-required in the mailform!