Esempio n. 1
0
 public function __construct($name = 'register-form', CaptchaOptions $options, $role = 'recruiter')
 {
     parent::__construct($name, []);
     $this->setAttribute('data-handle-by', 'native');
     $this->setAttribute('class', 'form-horizontal');
     $fieldset = new Fieldset('register');
     $fieldset->setOptions(array('renderFieldset' => true));
     $fieldset->add(array('type' => 'text', 'name' => 'name', 'options' => array('label' => 'Name')));
     $fieldset->add(array('type' => 'email', 'name' => 'email', 'options' => array('label' => 'Email'), 'attributes' => ['required' => true]));
     $fieldset->add(array('name' => 'role', 'type' => 'hidden', 'attributes' => array('value' => $role)));
     $this->add($fieldset);
     $mode = $options->getMode();
     if (in_array($mode, [CaptchaOptions::RE_CAPTCHA, CaptchaOptions::IMAGE])) {
         if ($mode == CaptchaOptions::IMAGE) {
             $captcha = new Image($options->getImage());
         } elseif ($mode == CaptchaOptions::RE_CAPTCHA) {
             $captcha = new ReCaptcha($options->getReCaptcha());
         }
         if (!empty($captcha)) {
             $this->add(array('name' => 'captcha', 'options' => array('label' => 'Are you human?', 'captcha' => $captcha), 'type' => 'Zend\\Form\\Element\\Captcha'));
         }
     }
     $buttons = new ButtonsFieldset('buttons');
     $buttons->add(array('type' => 'submit', 'name' => 'button', 'attributes' => array('type' => 'submit', 'value' => 'Register', 'class' => 'btn btn-primary')));
     $this->add(array('name' => 'csrf', 'type' => 'csrf', 'options' => array('csrf_options' => array('salt' => str_replace('\\', '_', __CLASS__), 'timeout' => 3600))));
     $this->add($buttons);
 }
Esempio n. 2
0
 public function testWithImageField()
 {
     $options = new CaptchaOptions();
     $options->setMode("image");
     $testedObject = new Register(null, $options);
     $captchaInput = $testedObject->get('captcha');
     $this->assertInstanceOf('Zend\\Captcha\\Image', $captchaInput->getOption('captcha'));
 }