Handling errors returned

The verifier() function of the form can return errors if the submitted field contents are not correct; which we will see in more detail later. To display these errors in the form’s HTML, there are CSS classes and a naming system which are employed:

At the top of the form there are general errors (or success messages):

  1. [<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>]
  2. [<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>]


For each field, there is a message and a CSS class on the list item to visually tag the error. The field message is calculated using the #ENV{erreurs} variable which provides all the field errors:

  1. #SET{erreurs,#ENV**{erreurs}|table_valeur{xxx}}
  2. <li class="editer_xxx obligatoire[ (#GET{erreurs}|oui)erreur]">
  3. [<span class='erreur_message'>(#GET{erreurs})</span>]
  4. </li>


This combines with the previous form to give:

  1. <div class="formulaire_spip formulaire_demo">
  2. [<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>]
  3. [<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>]
  5. <form action="#ENV{action}" method="post"><div>
  7. <ul>
  8. #SET{erreurs,#ENV**{erreurs}|table_valeur{la_demo}}
  9. <li class="editer_la_demo obligatoire[ (#GET{erreurs}|oui)erreur]">
  10. <label for="la_demo">La demo</label>
  11. [<span class='erreur_message'>(#GET{erreurs})</span>]
  12. <input type='text' name='la_demo' id='la_demo' value="#ENV{la_demo}" />
  13. </li>
  14. </ul>
  15. <p class="boutons"><input type="submit" class="submit" value="<:pass_ok:>" /></p>
  16. </div></form>


Author Mark Baber Published :

Translations : English, Español, français