Captcha::validate PHP Method

validate() public static method

Validate captcha.
public static validate ( mixed $value = null ) : boolean
$value mixed
return boolean validity of captcha submission
    public static function validate($value = null)
    {
        if (is_null($value)) {
            // Get captcha text
            $captchaText = null;
            Gdn::pluginManager()->EventArguments['captchatext'] =& $captchaText;
            Gdn::pluginManager()->fireAs('captcha')->fireEvent('get', ['captcha' => $value]);
            $value = $captchaText;
        }
        if (is_null($value)) {
            return false;
        }
        // Validate captcha text
        // Assume invalid submission
        $valid = false;
        Gdn::pluginManager()->EventArguments['captchavalid'] =& $valid;
        Gdn::pluginManager()->fireAs('captcha')->fireEvent('validate', ['captcha' => $value]);
        $isValid = $valid ? true : false;
        unset(Gdn::pluginManager()->EventArguments['captchavalid']);
        return $isValid;
    }

Usage Example

 /**
  * Validates the captcha.
  */
 protected function validateCaptcha()
 {
     if ($this->useCaptcha) {
         $this->captcha = new Captcha($this->captchaID);
         $this->captcha->validate($this->captchaString);
         $this->useCaptcha = false;
     }
 }
All Usage Examples Of Captcha::validate