root/trunk/lib/form/user/RegisterForm.class.php

Revision 53, 2.6 kB (checked in by nperriault, 2 years ago)
  • Ported signin form and action to 1.1 forms framework
  • lib folder layout changed
Line 
1 <?php
2 /**
3  * Member registration form
4  *
5  * @see sfGuardUserForm
6  */
7 class RegisterForm extends BasesfGuardUserForm
8 {
9
10   static protected
11     $forbidden_names = array('admin', 'niko', 'contact', 'info', 'infos', 'commercial', 'tech', 'support', 'sales', 'partnership', 'webmaster', 'business', 'owner');
12  
13   public function configure()
14   {
15     // widgets
16     $this->setWidgets(array(
17       'username'  => new sfWidgetFormInput(),
18       'email'     => new sfWidgetFormInput(),
19       'password'  => new sfWidgetFormInputPassword(),
20       'password2' => new sfWidgetFormInputPassword(),
21       'captcha'   => new sfWidgetFormReCaptcha(array('public_key' => sfConfig::get('app_recaptcha_public_key'))),
22     ));
23     
24     // helps
25     $this->widgetSchema->setHelps(array(
26       'username'  => 'Your username should contains only alphanumeric, dash, dot or underscore characters, and begin with a letter.',
27       'email'     => 'Please enter a valid email address. An activation link will be sent to this adress.',
28       'password'  => 'Your password must be 6 characters length minimum.',
29       'password2' => 'Please confirm your password for avoiding typos.',
30       'captcha'   => 'This codes aims at detecting if you are a bot or a human person.',
31     ));
32     
33     // validators
34     $this->setValidators(array(
35       'username'  => new sfValidatorAnd(array(
36         new sfValidatorString(array('min_length' => 3, 'max_length' => 20)),
37         new sfValidatorRegex(array('pattern' => '/^[a-zA-Z]([a-zA-Z0-9._-]+)$/'), array('invalid' => 'Name "%value%" contains forbidden characters')),
38         new sfValidatorBlacklist(array('choices' => self::$forbidden_names), array('invalid' => 'Name "%value%" is blacklisted')),
39       )),
40       'email'     => new sfValidatorAnd(array(
41         new sfValidatorString(array('max_length' => 100)),
42         new sfValidatorEmail(),
43       )),
44       'password'  => new sfValidatorString(array('min_length' => 6, 'max_length' => 128)),
45       'password2' => new sfValidatorString(array('min_length' => 6, 'max_length' => 128)),
46       'captcha'   => new sfValidatorReCaptcha(array('private_key' => sfConfig::get('app_recaptcha_private_key'))),
47     ));
48     
49     // post validator
50     $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
51       new sfValidatorSchemaCompare('password', 'equal', 'password2', array('throw_global_error' => true)),
52       new sfValidatorPropelUnique(array('model'  => 'sfGuardUser', 'column' => 'username')),
53       new sfValidatorPropelUnique(array('model'  => 'sfGuardUser', 'column' => 'email'))
54     )));
55     
56     $this->widgetSchema->setNameFormat('user[%s]');
57   }
58  
59 }
Note: See TracBrowser for help on using the browser.