Redaxscript\Html\Form::captcha PHP Method

captcha() public method

append the captcha
Since: 2.6.0
public captcha ( string $type = null ) : Form
$type string type of the captcha
return Form
    public function captcha($type = null)
    {
        /* task */
        if ($this->_optionArray['captcha'] && $type === 'task') {
            $this->label('* ' . $this->_captcha->getTask(), ['for' => 'task']);
            /* number */
            $this->number(['id' => 'task', 'min' => $this->_captcha->getMin(), 'max' => $this->_captcha->getMax() * 2, 'name' => 'task', 'required' => 'required']);
        }
        /* solution */
        if ($this->_optionArray['captcha'] && $type === 'solution') {
            $captchaHash = new Hash(Config::getInstance());
            $captchaHash->init($this->_captcha->getSolution());
            /* hidden */
            $this->hidden(['name' => 'solution', 'value' => $captchaHash->getHash()]);
        }
        return $this;
    }

Usage Example

Example #1
0
 /**
  * render the view
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function render()
 {
     $output = Hook::trigger('loginFormStart');
     $outputLegend = null;
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h2', ['class' => 'rs-title-content'])->text($this->_language->get('login'));
     if (Db::getSetting('recovery')) {
         $linkElement = new Html\Element();
         $linkElement->init('a', ['href' => $this->_registry->get('parameterRoute') . 'login/recover']);
         $outputLegend = $linkElement->text($this->_language->get('recovery_question') . $this->_language->get('question_mark'));
     }
     $formElement = new Html\Form($this->_registry, $this->_language);
     $formElement->init(['form' => ['class' => 'rs-js-validate-form rs-form-default rs-form-login'], 'button' => ['submit' => ['name' => get_class()]]], ['captcha' => Db::getSetting('captcha') > 0]);
     /* create the form */
     $formElement->append('<fieldset>')->legend($outputLegend)->append('<ul><li>')->label('* ' . $this->_language->get('user'), ['for' => 'user'])->text(['autofocus' => 'autofocus', 'id' => 'user', 'name' => 'user', 'pattern' => '[a-zA-Z0-9]{1,30}', 'required' => 'required'])->append('</li><li>')->label('* ' . $this->_language->get('password'), ['for' => 'password'])->password(['id' => 'password', 'name' => 'password', 'pattern' => '[a-zA-Z0-9]{1,30}', 'required' => 'required'])->append('</li>');
     if (Db::getSetting('captcha') > 0) {
         $formElement->append('<li>')->captcha('task')->append('</li>');
     }
     $formElement->append('</ul></fieldset>');
     if (Db::getSetting('captcha') > 0) {
         $formElement->captcha('solution');
     }
     $formElement->token()->submit();
     /* collect output */
     $output .= $titleElement . $formElement;
     $output .= Hook::trigger('loginFormEnd');
     return $output;
 }
All Usage Examples Of Redaxscript\Html\Form::captcha