| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
class RegisterForm extends BasesfGuardUserForm |
|---|
| 8 |
{ |
|---|
| 9 |
|
|---|
| 10 |
* Form configuration |
|---|
| 11 |
* |
|---|
| 12 |
*/ |
|---|
| 13 |
public function configure() |
|---|
| 14 |
{ |
|---|
| 15 |
|
|---|
| 16 |
$this->setWidgets(array( |
|---|
| 17 |
'username' => new sfWidgetFormInput(), |
|---|
| 18 |
'email' => new sfWidgetFormInput(), |
|---|
| 19 |
'password' => new sfWidgetFormInputPassword(), |
|---|
| 20 |
'password2' => new sfWidgetFormInputPassword(), |
|---|
| 21 |
)); |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
$this->widgetSchema->setHelps(array( |
|---|
| 25 |
'username' => 'Your username should contains only alphanumeric, dash, dot or underscore characters, and begin with a letter.', |
|---|
| 26 |
'email' => 'Please enter a valid email address. An activation link will be sent to this adress.', |
|---|
| 27 |
'password' => 'Your password must be 6 characters length minimum.', |
|---|
| 28 |
'password2' => 'Please confirm your password for avoiding typos.', |
|---|
| 29 |
)); |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
$this->setValidators(array( |
|---|
| 33 |
'username' => new sfValidatorAnd(array( |
|---|
| 34 |
new sfValidatorString(array('min_length' => 3, 'max_length' => 20)), |
|---|
| 35 |
new sfValidatorRegex(array('pattern' => '/^[a-zA-Z]([a-zA-Z0-9._-]+)$/'), array('invalid' => 'Name "%value%" contains forbidden characters')), |
|---|
| 36 |
new sfValidatorBlacklist(array('forbidden_values' => sfConfig::get('app_people_forbidden_names', array())), array('invalid' => 'Name "%value%" is blacklisted')), |
|---|
| 37 |
)), |
|---|
| 38 |
'email' => new sfValidatorAnd(array( |
|---|
| 39 |
new sfValidatorString(array('max_length' => 100)), |
|---|
| 40 |
new sfValidatorEmail(), |
|---|
| 41 |
)), |
|---|
| 42 |
'password' => new sfValidatorString(array('min_length' => 6, 'max_length' => 128)), |
|---|
| 43 |
'password2' => new sfValidatorString(array('min_length' => 6, 'max_length' => 128)), |
|---|
| 44 |
)); |
|---|
| 45 |
|
|---|
| 46 |
$this->addCaptcha(); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
$this->validatorSchema->setPostValidator(new sfValidatorAnd(array( |
|---|
| 50 |
new sfValidatorSchemaCompare('password', 'equal', 'password2'), |
|---|
| 51 |
new sfValidatorPropelUnique(array('model' => 'sfGuardUser', 'column' => 'username')), |
|---|
| 52 |
new sfValidatorPropelUnique(array('model' => 'sfGuardUser', 'column' => 'email')) |
|---|
| 53 |
))); |
|---|
| 54 |
|
|---|
| 55 |
$this->widgetSchema->setNameFormat('user[%s]'); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* Adds a captcha to current form, if enabled by configuration |
|---|
| 60 |
* |
|---|
| 61 |
*/ |
|---|
| 62 |
public function addCaptcha() |
|---|
| 63 |
{ |
|---|
| 64 |
if (true === sfConfig::get('app_recaptcha_enabled')) |
|---|
| 65 |
{ |
|---|
| 66 |
$this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array('public_key' => sfConfig::get('app_recaptcha_public_key'))); |
|---|
| 67 |
$this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array('private_key' => sfConfig::get('app_recaptcha_private_key'))); |
|---|
| 68 |
$this->widgetSchema->setHelp('captcha', 'This codes aims at detecting if you are a bot or a human person.'); |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|