Sample Form Error Handling Examples
Step 1: Setup the Input Requirements
Under this validation tool. Most validation requirements for each input are configured within the HTML code of that input element. This requires usage of HTML5 data attributes. In this case, all validation attributes will starrt as 'data-val-*'. The Asterisk is for additional and more specific requirements.
Example: A required text field:
<input type="text" name="first_name" maxlength="10" data-val-required="1" data-val-min-length="3" />
Step 2: Setup the HTML Markup
All elements should be inside of a form tag <form>. In addition, the form input needs to have a generally specific HTML structure for this validation scheme to work. The required elements are:
1. An input wrapper: Please a DIV or LABEL tag. Label tags are preferred. If using a div tag, please make sure to add a CSS class name such as 'row', 'label' or 'text', 'textarea', 'checkbox'
<label class="text" for="first_name"/>
<input type="text" name="first_name" id="first_name" maxlength="10" data-val-required="1" data-val-min-length="3" />
</label>
OR
<div class="row text" for="first_name"/>
<input type="text" name="first_name" id="first_name" maxlength="10" data-val-required="1" data-val-min-length="3" />
</div>
* Please note for checkboxes and radio button groups, check additional documentation on HTML markup.
Example:
1. An input wrapper: Please a DIV or LABEL tag. Label tags are preferred. If using a div tag, please make sure to add a CSS class name such as 'row', 'label' or 'text', 'textarea', 'checkbox'
<label class="text" for="first_name"/>
<input type="text" name="first_name" id="first_name" maxlength="10" data-val-required="1" data-val-min-length="3" />
</label>
OR
<div class="row text" for="first_name"/>
<input type="text" name="first_name" id="first_name" maxlength="10" data-val-required="1" data-val-min-length="3" />
</div>
* Please note for checkboxes and radio button groups, check additional documentation on HTML markup.Example:
2. An Input Label: You can also setup field labels. However, they are optional, except for checkboxes and radio buttons.
<label class="text" for="first_name"/>
<span>First Name</span>
<input type="text" name="first_name" id="first_name" maxlength="10" data-val-required="1" data-val-min-length="3" />
</label>
Example: