Making a field required

A required field simply has a validator called required added to it. You can use the method addValidator() on your element to add the required validator. In process.php enter code on a new line to add the validator, for example if you wanted to make the name field required, search for the term $name and add the highlighted line of code as shown below.

1
2
34
$name = new Quform_Element('name');
$name->addFilter('trim');
$name->addValidator('required');$form->addElement($name);
$name = new Quform_Element('name');
$name->addFilter('trim');
$name->addValidator('required');
$form->addElement($name);

It may also be a good idea to add an asterisk to the element label on your web page to let users know that the element is now required. Here is the preset HTML we have for this on a form element label (the <span> is the part you want to copy):

1
<label>Name <span class="quform-required">*</span></label>
<label>Name <span class="quform-required">*</span></label>
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy