Quel est le meilleur moyen de mettre à jour la classe de formulaire dans RSForm! Pro si le message d'erreur est affiché?
Cela pourrait-il être fait en utilisant jQuery ou un script PHP?
Le code lorsque l'erreur est affichée est:
<form action="http://webaddresshere.com" enctype="multipart/form-data" class="formResponsive" id="userForm" method="post"><p class="error">Please complete all required fields!</p>
<h2>Inapub in your inbox</h2>
<!-- Do not remove this ID, it is used to identify the page so that the pagination script can work correctly -->
<fieldset id="rsform_5_page_0" class="formHorizontal formContainer">
<div class="rsform-block rsform-block-intro">
<p>Subscribe to our newsletter today to recieve the latest blogs and stories from the team and exclusive product offers</p>
</div>
<div class="rsform-block rsform-block-full-name">
<div class="formBody"><input type="text" class="rsform-input-box" onfocus="this.value=''" id="Full name" name="form[Full name]" size="20" value="Full name"><span class="formValidation"><span class="formNoError" id="component47">Please enter your full name</span></span></div>
</div>
<div class="rsform-block rsform-block-email-address">
<div class="formBody"><input type="text" class="rsform-input-box rsform-error" onfocus="this.value=''" id="email address" name="form[email address]" size="20" value="email address"></div>
</div>
<div class="rsform-block rsform-block-pubsupplier">
<div class="formBody"><input type="checkbox" id="PubSupplier0" value="I work in a pub" name="form[PubSupplier][]"><label for="PubSupplier0">I work in a pub</label><input type="checkbox" id="PubSupplier1" value="I am a supplier" name="form[PubSupplier][]"><label for="PubSupplier1">I am a supplier</label></div>
</div>
<div class="rsform-block rsform-block-over-18">
<div class="formBody"><input type="checkbox" id="Over 180" value="I confirm I'm over 18" name="form[Over 18][]"><label for="Over 180">I confirm I'm over 18</label></div>
</div>
<span class="formValidation"><span class="formError" id="component48">Please enter a valid email address</span></span>
<span class="formValidation"><span class="formError" id="component49">Please state you profession</span></span>
<span class="formValidation"><span class="formError" id="component50">Please confirm you are over 18.</span></span>
<div class="rsform-block rsform-block-subscribe">
<div class="formBody"><input type="submit" class="rsform-submit-button" id="Subscribe" name="form[Subscribe]" value="Subscribe"><span class="formValidation"></span></div>
</div>
</fieldset>
<input type="hidden" value="5" name="form[formId]"></form>
Lorsque l'erreur, veuillez remplir tous les champs obligatoires!
Vous ne savez pas comment RSForm! Pro affiche un message d'erreur, mais je suppose qu'il existe un élément HTML prédéfini avec une classe définie sur display: block
s'il y a une erreur.
Donc, ce que je suggérerais de faire est de faire apparaître l'erreur, puis d'inspecter l'élément error et de rechercher d'éventuelles classes, vous pouvez alors utiliser le jQuery suivant:
jQuery(document).ready(function($){
var errorMsg = $('.formError');
if( errorMsg.is(':visible') ){
errorMsg.parents('.formResponsive').addClass('something');
}
});