Checking the submitted values

The verifier() function is used to analyse the values posted and return errors that may exist concerning the data entered. To do this, the function returns a paired "field" / "error message" array of the offending fields, and also possibly a general message for the whole of the form using the "message_erreur" key.

The form processing function will be called on ONLY if the table returned is empty. If it is not, the form is redisplayed with the various error messages that have been passed.

function formulaire_nom_verifier_dist() {
	$erreurs = array();
	foreach(array('titre','texte') as $champ) {
		if (!_request($champ)) {
			$erreurs[$champ] = "This data is mandatory!";
		}
	}
	if (count($erreurs)) {
		$erreurs['message_erreur'] = "An error occured in your data entry";
	}
	return $erreurs;
}

The formulaire_verifier pipeline is used to supplement the list of returned errors.

Example

The "Amis" (Friends) plugin has a form for inviting people to become your friend! The verifier() function checks that the mail address of the person being invited is correctly formatted:

function formulaires_inviter_ami_verifier_dist(){

	$erreurs = array();
	foreach(array('email') as $obli)
		if (!_request($obli))
			$erreurs[$obli] = (isset($erreurs[$obli])?$erreurs[$obli]:'') . _T('formulaires:info_obligatoire_rappel');

	if ($e=_request('email')){
		if (!email_valide($e))
			$erreurs['email'] = (isset($erreurs['email'])?$erreurs['email']:'') . _T('formulaires:email_invalide');
	}

	return $erreurs;
}

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français