Bonjour,
Je suis actuellement confronter à un problème de formulaire. Le but étant de créer un formulaire représentant les informations d'un utilisateur stocké dans la base selon son "profil" dans mon cas j'ai choisi d'utiliser les embedForm.
Voici ma classe actions dans laquelle je génère et sauve le formulaire :
Voici mon _form.php pour le rendu du formulaire :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 class informationsActions extends sfActions { public function executeEdit(sfWebRequest $request) { $idtiers = Doctrine::getTable('UTILISATEUR')->find($this->getUser()->getAttribute('id'))->getidtiers(); $this->form = new TIERSForm(Doctrine::getTable('TIERS')->find($idtiers)); if($this->getUser()->hasAttribute('IDAUDITEUR')) { $this->form->embedForm("auditeur",new AUDITEURForm(Doctrine::getTable('AUDITEUR')->find($this->getUser()->getAttribute('IDAUDITEUR')))); } if($this->getUser()->hasAttribute('IDCLIENT')) { $this->form->embedForm("client",new CLIENTForm(Doctrine::getTable('CLIENT')->find($this->getUser()->getAttribute('IDCLIENT')))); } if($request->isMethod("post")) { $this->processForm($request, $this->form); } } protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { $user = $form->save(); $this->redirect('informations/edit'); } } }
Enfin voici mon fichier TIERSForm.class.php et EditSuccess.php :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 <?php include_stylesheets_for_form($form) ?> <?php include_javascripts_for_form($form) ?> <form action="<?php echo url_for('informations/edit') ?>" method="post"> <?php echo $form->renderHiddenFields() ?> <?php echo $form->renderGlobalErrors() ?> <table style="border-collapse: separate;"> <tr> <th colspan="2">Mon profil :</th> </tr> <tr> <td class="information" colspan="2"><b>Information :</b> les champs marqués d'un * sont obligatoires.</td> </tr> <tr> <th class="partie" colspan="2">Etat civil :</th> </tr> <tr> <td class="colonne-libelle" width="150"><?php echo $form['idcivilite']->renderLabel() ?> * :</td> <td class="colonne-champ" width="400"><?php echo $form['idcivilite'] ?></td> <?php echo $form['idcivilite']->renderError() ?> </tr> <tr> <td class="colonne-libelle"><?php echo $form['nomtiers']->renderLabel() ?> * :</td> <td class="colonne-champ"><?php echo $form['nomtiers'] ?></td> <td><?php echo $form['nomtiers']->renderError() ?></td> </tr> <tr> <td class="colonne-libelle"><?php echo $form['prenomtiers']->renderLabel() ?> :</td> <td class="colonne-champ"><?php echo $form['prenomtiers'] ?></td> <?php echo $form['prenomtiers']->renderError() ?> </tr> <tr> <th class="partie" colspan="2">Contact :</th> </tr> <tr> <td class="colonne-libelle"><?php echo $form['emailtiers']->renderLabel() ?> :</td> <td class="colonne-champ"><?php echo $form['emailtiers'] ?></td> <?php echo $form['emailtiers']->renderError() ?> </tr> <tr> <td class="colonne-libelle"><?php echo $form['numtelephone1tiers']->renderLabel() ?> :</td> <td class="colonne-champ"><?php echo $form['numtelephone1tiers'] ?></td> <?php echo $form['numtelephone1tiers']->renderError() ?> </tr> <!-- Affichage du formulaire pour un auditeur --> <?php if ($user->hasAttribute('IDAUDITEUR')): ?> <tr> <th class="partie" colspan="2">Infos Auditeur:</th> </tr> <?php endif; ?> <!-- Affichage du formulaire pour un client --> <?php if ($user->hasAttribute('IDCLIENT')): ?> <tr> <th class="partie" colspan="2">Infos Client:</th> </tr> <tr> <td class="colonne-libelle"><?php echo $form['client']['idconditionpaiement']->renderLabel() ?> * :</td> <td class="colonne-champ"><?php echo $form['client']['idconditionpaiement'] ?></td> <?php echo $form['client']['idconditionpaiement']->renderError() ?> </tr> <tr> <td class="colonne-libelle"><?php echo $form['client']['siretclient']->renderLabel() ?> :</td> <td class="colonne-champ"><?php echo $form['client']['siretclient'] ?></td> <?php echo $form['client']['siretclient']->renderError() ?> </tr> <?php endif; ?> </table> <input type="submit" value="Mettre à jour mon profil" /> </form>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 <?php /** * TIERS form. * * @package form * @subpackage TIERS * @version SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ */ class TIERSForm extends BaseTIERSForm { public function configure() { unset($this['descriptiontiers'],$this['commentairetiers'] ,$this['idformateur'],$this['idville'],$this['vil_idville'] ,$this['idprospect'],$this['idfinanceur'] ,$this['idpartenaire'],$this['idorganismeaccueil']); $years = range(date('Y') - 70 , date('Y') ); $this->setWidgets(array( 'idtiers' => new sfWidgetFormInputHidden(), 'idcivilite' => new sfWidgetFormDoctrineChoice(array('model' => 'CIVILITE', 'add_empty' => false)), 'nomtiers' => new sfWidgetFormInput(), 'acedextiers' => new sfWidgetFormInput(), 'prenomtiers' => new sfWidgetFormInput(), 'datenaissancetiers' => new sfWidgetFormDate(array('years'=>array_combine($years, $years))), 'adressetiers' => new sfWidgetFormInput(), 'complementadressetiers' => new sfWidgetFormInput(), 'bptiers' => new sfWidgetFormInput(), 'acedextiers' => new sfWidgetFormInputCheckbox(), 'cedextiers' => new sfWidgetFormInput(), 'emailtiers' => new sfWidgetFormInput(), 'numtelephone1tiers' => new sfWidgetFormInput(), 'numtelephone2tiers' => new sfWidgetFormInput(), 'numfaxtiers' => new sfWidgetFormInput(), 'idauditeur' => new sfWidgetFormInputHidden(), 'idclient' => new sfWidgetFormInputHidden(), )); $this->widgetSchema->setLabels(array( 'idtiers' => 'Tiers', 'idcivilite' => 'Civilité', 'nomtiers' => 'Nom', 'prenomtiers' => 'Prénom', 'datenaissancetiers' => 'Date de naissance', 'adressetiers' => 'Adresse', 'complementadressetiers' => 'Complément adresse', 'bptiers' => 'BP', 'acedextiers' => 'Cedex', 'cedextiers' => 'n° cedex', 'emailtiers' => 'Email', 'numtelephone1tiers' => 'n° de téléphone', 'numtelephone2tiers' => 'n° de téléphone alt', 'numfaxtiers' => 'Fax', )); $this->setValidators(array( 'idtiers' => new sfValidatorDoctrineChoice(array('model' => 'TIERS', 'column' => 'idtiers', 'required' => true)), 'idcivilite' => new sfValidatorDoctrineChoice(array('model' => 'CIVILITE', 'column' => 'idcivilite' , 'required' => true)), 'nomtiers' => new sfValidatorString(array('max_length' => 255, 'required' => true),array('required' => 'Veuillez saisir votre nom')), 'prenomtiers' => new sfValidatorString(array('max_length' => 255, 'required' => false)), 'datenaissancetiers' => new sfValidatorDate(array('required' => false)), 'adressetiers' => new sfValidatorString(array('max_length' => 255, 'required' => false)), 'complementadressetiers' => new sfValidatorString(array('max_length' => 255, 'required' => false)), 'bptiers' => new sfValidatorString(array('max_length' => 20, 'required' => false)), 'acedextiers' => new sfValidatorInteger(array('required' => false)), 'cedextiers' => new sfValidatorString(array('max_length' => 20, 'required' => false)), 'emailtiers' => new sfValidatorString(array('max_length' => 255, 'required' => false)), 'numtelephone1tiers' => new sfValidatorString(array('max_length' => 30, 'required' => false)), 'numtelephone2tiers' => new sfValidatorString(array('max_length' => 30, 'required' => false)), 'numfaxtiers' => new sfValidatorString(array('max_length' => 30, 'required' => false)), 'idauditeur' => new sfValidatorDoctrineChoice(array('model' => 'AUDITEUR', 'required' => false)), 'idclient' => new sfValidatorDoctrineChoice(array('model' => 'CLIENT', 'required' => false)), )); } }
Malgré mes efforts le formulaire reste impossible à enregistrer que ce soit avec un tiers disposant du statut d'auditeur ou d'un tiers sans aucun statut.Code:
1
2
3
4 <?php use_stylesheet('template.css') ?> <?php include_partial('form', array('form'=>$form,'user'=>$sf_user)) ?>
Le premier affichage se fait sans problème et avec les bonnes informations mais dès la soumission de mon formulaire aucun de mes validateurs ne passe, les erreur suivante s'affichent :
Si quelqu'un à une solution je suis preneur.Citation:
* Tiers: Required.
* csrf token: Required.
* Required.
* Veuillez saisir votre nom
Merci.