I have this problem, when I load my form, the validation messages appears in the first load of the page,I don’t know why ..
and this is my Action
is it Wrong if the first load action come from a Get not a Post ..I’m confused ..
public function inscriptionAction() {
$form = new Application_Form_Inscription ();
$form->submit->setLabel ( 'Inscription' );
$this->view->form = $form;
if ($this->getRequest ()->isPost ()) {
$formData = $this->getRequest ()->getPost ();
if ($form->isValid ( $formData )) {
// ton form est valide
// => enregistrement des données
// => redirection éventuelle
$nomU = $form->getValue ( 'nomU' );
$prenomU = $form->getValue ( 'prenomU' );
$mailU = $form->getValue ( 'mailU' );
$dateN = $form->getValue ( 'dateN' );
$civilite = $form->getValue ( 'civilite' );
$villeU = $form->getValue ( 'villeU' );
$passW = $form->getValue ( 'passW' );
$passw2 = $form->getValue ( 'repassW' );
$recevoirNews = ( int ) $form->getValue ( 'recevoirNews' );
$utilisateurs = new Application_Model_DbTable_Utilisateurs ();
$utilisateurs->ajouterUtilisateur ( $nomU, $prenomU, $mailU, $passW, $civilite, $dateN, $recevoirNews, $villeU );
$this->_helper->redirector ( 'index' );
} else {
// ton form est invalide
// réinjecte les valeurs saisies par l'user
// nouvel affichage du formulaire
$form->populate ( $formData );
}
} else {
// initialisation et 1er affichage du formulaire
}
}
thank’s
Nothing wrong with the first load of the form appearing on page via GET.
Perhaps there is something in the last else block (“// initialisation et 1er affichage du formulaire”) that is triggering the validation?
My usual form generate/display/submit flow does not explicitly call
$form->populate($formData); the call to$form->isValid($formData)does that for me.My flow usually looks like this: