14use Gregwar\Captcha\CaptchaBuilder;
15use Gregwar\Captcha\PhraseBuilder;
44 parent::setDefaults();
45 $this->defaults[
'defaultValue'] =
false;
46 $this->defaults[
'errorMessage'] = _(
'Please fill in the correct phrase.');
47 $this->defaults[
'textColor'] =
false;
48 $this->defaults[
'backgroundColor'] =
false;
49 $this->defaults[
'width'] = 250;
50 $this->defaults[
'height'] = 100;
62 $this->captcha =
new CaptchaBuilder();
64 parent::__construct(
$name, $parameters, $form);
66 if (is_array($this->textColor)) {
67 $this->captcha->setTextColor($this->textColor[0], $this->textColor[1], $this->textColor[2]);
69 if (is_array($this->backgroundColor)) {
70 $this->captcha->setBackgroundColor($this->backgroundColor[0], $this->backgroundColor[1], $this->backgroundColor[2]);
84 if (is_bool($newValue)) {
85 $this->value = $newValue;
87 $this->value = $newValue;
114 if (!$this->validated) {
115 $this->validated =
true;
117 $this->valid = $this->value ===
true || $this->
testPhrase($this->value);
130 $this->captcha->setPhrase($this->sessionSlot[
'formCaptcha'] ??
"");
132 if (!$this->captcha->testPhrase(
$value)) {
147 $phraseBuilder =
new PhraseBuilder();
148 $phrase = $phraseBuilder->build();
150 $this->captcha->setPhrase($phrase);
151 $this->sessionSlot[
'formCaptcha'] = $phrase;
161 $type = strtolower($this->type);
164 $label = $this->htmlLabel();
170 if (empty($this->sessionSlot[
'formCaptcha'])) {
174 $this->captcha->build($this->width, $this->height);
176 return "<p {$wrapperAttributes}>" .
178 "<span class=\"depage-label\">{$label}{$marker}</span>" .
179 "<span class=\"captcha-img\">" .
180 "<img src=\"" . $this->captcha->inline() .
"\" />" .
182 "<input name=\"{$this->name}\" type=\"{$type}\"{$inputAttributes} value=\"$value\">" .
$valid
Contains element validation status/result.
$value
Input elements's value.
$label
Input element - HTML label.
$errorMessage
Message that gets displayed in case of invalid input.
htmlHelpMessage()
Returns HTML-rendered helpMessage.
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
htmlMarker()
Returns elements' required-indicator.
$type
Input element type - HTML input type attribute.
$helpMessage
Extra help message.
htmlValue()
Returns HTML-rendered element value.
$marker
Input element - HTML marker text that marks required fields.
htmlErrorMessage()
Returns HTML-rendered error message.
testPhrase($value)
testPhrase
validate()
validates boolean input element value
__construct($name, $parameters, $form)
__construct
__toString()
Renders element to HTML.
setSessionSlot(&$sessionSlot)
setSessionSlot
setValue($newValue)
set the boolean element value
getNewPhrase()
getNewPhrase
setDefaults()
collects initial values across subclasses.
htmlInputAttributes()
renders text element specific HTML attributes
htmlList($options=null)
Renders HTML datalist.
Classes for HTML input-elements.