I have a WordPress website and I'm using the "Contact Form 7" plugin to create forms. While they provide shortcodes, I had to resort to using HTML to customize it for my client's specific requirements.
Within the form, ARIA attributes and role="alter" are used to display error messages when validation fails. However, I am struggling to figure out how to add the desired class to the failed validation boxes.
Below is the current HTML structure:
<div class="browser_gecko form_wrapper wpcf7" id="wpcf7-f46-p47-o1" lang="en-US" dir="ltr">
<div class="screen-reader-response"></div>
<form action="/form/#wpcf7-f46-p47-o1" method="post" class="wpcf7-form" novalidate="novalidate">
<div style="display: none;">
<input type="hidden" name="_wpcf7" value="46" />
<input type="hidden" name="_wpcf7_version" value="4.1.1" />
<input type="hidden" name="_wpcf7_locale" value="en_US" />
<input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f46-p47-o1" />
<input type="hidden" name="_wpnonce" value="229223424d" />
</div>
<div class="wpcf7-response-output wpcf7-display-none validation_error"></div>
<div class='form_body'>
<ul class='form_fields top_label description_below'>
<li class='field field_contains_required' >
<label class='field_label'>Name<span class='field_required'>*</span></label>
<div class='input_container'><input type='text' name='your-name' class="large wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" tabindex='1' /></div>
</li>
<li class='field'><label class='field_label'>Company</label>
<div class='input_container'><input type='text' name='COMPANY' class="large wpcf7-form-control wpcf7-text" aria-invalid="false" tabindex='2' /></div>
</li>
<li id='field_4' class='field field_contains_required' ><label class='field_label'>Email<span class='field_required'>*</span></label>
<div class='input_container'><input type='email' name='your-email' class="large pcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" tabindex='3' aria-required="true" aria-invalid="false" /></div></li>
<li id='field_5' class='field field_contains_required'><label class='field_label'>Inquiry<span class='field_required'>*</span></label>
<div class='input_container'><textarea name='your-message' tabindex='4' rows='10' cols='50' class="textarea medium wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required" aria-required="true" aria-invalid="false"></textarea></div></li>
</ul>
</div>
<div class='form_footer top_label'><input type='submit' value='Submit' class="button gform_button wpcf7-form-control wpcf7-submit" /></div>
</form>
</div>
I am looking to include the class "form_error" in the "li" elements that fail validation. Is there any guidance on how to achieve this?