Bonjour, j'ai quelques problèmes avec un formulaire. Je voulais tester de faire une section membre, j'ai donc créer mon module en frontend, j'édite tout ça, le rendus marche bien, les labels sont la, les helpers aussi, mais quand je valide il ne m'affiche pas les erreurs, je comprend pas pourquoi. A priori je n'ai pas d'erreurs syntaxiques dans mon code.
Je dois avoir un problème dans mes validators :
UserForm.class.php
_form.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 $this->validatorSchema->setPostValidator( new sfValidatorAnd( array( new sfValidatorSchemaCompare( 'pass', sfValidatorSchemaCompare::EQUAL, 'repass', array(), array('invalid' => "The password and password confirmation are different") ), new sfAnotherValidatorSchemaReCaptcha($this, 'captcha') ) ) ); $this->setValidators( array( 'login' => new sfValidatorAnd( array( new sfValidatorString( array( 'required' => true, 'min_length' => 3, 'max_length' => 14 ), array( 'min_length' => "The login is too short. 3 characters minimum.", 'max_length' => "The login is too long. 14 characters maximum", ) ), new sfValidatorRegex( array('pattern' => '/^[a-zA-Z0-9-]+$/') ) ), array(), array( 'required' => "The login is required", 'invalid' => "The nickname could not contain special characters." ) ), 'pass' => new sfValidatorString( array( 'required' => true, 'min_length' => 6, 'max_length' => 30 ), array( 'min_length' => "The password is too short. 6 characters minimum.", 'max_length' => "The password is too long. 30 characters maximum", 'required' => "Password is required", 'invalid' => "The password must contains between 6 and 30 characters" ) ), 'repass' => new sfValidatorString( array( 'required' => true, 'min_length' => 6, 'max_length' => 30 ), array( 'min_length' => "The password is too short. 6 characters minimum.", 'max_length' => "The password is too long. 30 characters maximum", 'required' => "Password confirmation is required", 'invalid' => "The password must contains between 6 and 30 characters" ) ), 'mail' => new sfValidatorEmail( array('required' => true), array( 'required' => "Email is required", 'invalid' => "This email isn't correct. Please give a valid one." ) ) ) );
actions.class.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <form action="<?php echo url_for('create_account'); ?>" method="post" id="myform"> <fieldset> <legend><?php echo 'Create your account'?></legend> <ul class='formRegister'> <?php if ($form->hasGlobalErrors()): ?> <?php foreach ($form->getGlobalErrors() as $name => $error): ?> <li class='error'><?php echo $error ?></li> <?php endforeach; ?> <?php endif; ?> <?php foreach ($form as $widget): ?> <?php if ($widget->hasError()): ?> <li class='error'><?php echo $widget->getError(); ?></li> <?php endif; ?> <?php if (!$widget->isHidden()) { ?> <li> <span> <?php echo $widget->renderLabel(); ?> <?php echo $widget->renderHelp() ?> </span> <?php echo $widget->render() ?> </li> <?php } else { ?> <li><?php echo $widget->render() ?></li> <?php } ?> <?php endforeach; ?> </ul> <p><input type="submit" id='submit' value="<?php echo 'Register'?>" /></p> </fieldset> </form>
Voila, j'espère que vous verez plus clair que moi :s
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { $users = $form->save(); // On set les valeurs par défaut $users->setHostname($_SERVER['REMOTE_ADDR']); $users->setCreate(date('Y-m-d H:i:s')); $users->setUpdate(date('Y-m-d H:i:s')); $users->setConnect(date('Y-m-d H:i:s')); $users->setSignature(""); $users->setPicture("default"); $users->setValid(0); $users->setRoleId(2); // 1 = Membre / 9 = Admin $users->setEtat(0); // 0 = Non activé / 1 = Actif / 2 = Banni $users->save(); $this->redirect('register/edit?id='.$users->getId()); } }
Merci d'avance
Partager