public function __construct() { parent::__construct('login'); $this->setAttribute('method', 'post'); $this->setAttribute('class', 'form-horizontal'); $this->setAttribute('enctype', 'multipart/form-data'); $this->add(array('name' => 'username', 'attributes' => array('type' => 'text', 'class' => 'form-control', 'placeholder' => 'nombre de usuario'), 'options' => array('label' => 'username', 'label_attributes' => array('class' => 'col-sm-3 control-label')))); $this->add(array('name' => 'password', 'attributes' => array('type' => 'password', 'id' => 'password', 'maxlength' => 20, 'class' => 'form-control', 'placeholder' => 'Contraseña'), 'options' => array('label' => 'password', 'label_attributes' => array('class' => 'col-sm-3 control-label')))); $captchaImage = new CaptchaImage(); $captchaImage->setFont("public/resource/fonts/arial.ttf"); $captchaImage->setImgDir("public/resource/images"); $captchaImage->setImgUrl("/resource/images"); $captchaImage->setImgAlt("Captcha"); $captchaImage->setWidth(250); $captchaImage->setHeight(80); $captchaImage->setDotNoiseLevel(50); $captchaImage->setLineNoiseLevel(5); $captchaImage->setFontSize(38); $captchaImage->setExpiration(1); $captchaImage->setWordlen(6); $captchaImage->setMessage("El código no coincide, actualízalo y vuelve a intentarlo", $captchaImage::BAD_CAPTCHA); $this->add(array('type' => 'Zend\\Form\\Element\\Captcha', 'attributes' => array('type' => 'password', 'class' => 'form-control', 'placeholder' => 'captcha'), 'name' => 'captcha', 'options' => array('captcha' => $captchaImage, 'id' => 'captcha', 'label' => 'captcha', 'label_attributes' => array('class' => 'col-sm-2 control-label')))); $this->add(array('type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'csrf', 'options' => array('csrf_options' => array('timeout' => 600)))); $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Ingresar', 'class' => 'btn btn-primary btn-sm btn-sm'))); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $sessionKey = sprintf('%s_zend_captcha_session_key_%s', $form->getParent()->getName(), $form->getName()); $captcha = new Image(); if (isset($options['suffix'])) { $captcha->setSuffix($options['suffix']); } if (isset($options['height'])) { $captcha->setHeight($options['height']); } if (isset($options['width'])) { $captcha->setWidth($options['width']); } if (isset($options['img_alt'])) { $captcha->setImgAlt($options['img_alt']); } if (isset($options['font_size'])) { $captcha->setFontSize($options['font_size']); } if (isset($options['dot_noise_level'])) { $captcha->setDotNoiseLevel($options['dot_noise_level']); } if (isset($options['line_noise_level'])) { $captcha->setLineNoiseLevel($options['line_noise_level']); } if (isset($options['word_len'])) { $captcha->setWordlen($options['word_len']); } if (isset($options['expiration'])) { $captcha->setExpiration($options['expiration']); } if (isset($options['gc_freq'])) { $captcha->setGcFreq($options['gc_freq']); } $captcha->setImgDir($this->options['img_dir']); $captcha->setFont($this->options['font']); $captcha->setImgUrl($this->options['img_url']); $captcha->getWord(); $captcha->generate(); $this->session->set($sessionKey, $captcha->getSession()->getName()); $view->vars = array_merge($view->vars, array('img_url' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix(), 'height' => $captcha->getHeight(), 'width' => $captcha->getWidth(), 'img_alt' => $captcha->getImgAlt(), 'img_id' => $captcha->getId(), 'value' => "")); }