13namespace Depage\HtmlForm\Elements;
15use Gregwar\Captcha\CaptchaBuilder;
16use Gregwar\Captcha\PhraseBuilder;
50 parent::setDefaults();
51 $this->defaults[
'defaultValue'] =
false;
52 $this->defaults[
'errorMessage'] = _(
'Please fill in the correct phrase.');
53 $this->defaults[
'textColor'] =
false;
54 $this->defaults[
'backgroundColor'] =
false;
55 $this->defaults[
'width'] = 250;
56 $this->defaults[
'height'] = 100;
68 $this->captcha =
new CaptchaBuilder();
70 parent::__construct(
$name, $parameters, $form);
72 if (is_array($this->textColor)) {
73 $this->captcha->setTextColor($this->textColor[0], $this->textColor[1], $this->textColor[2]);
75 if (is_array($this->backgroundColor)) {
76 $this->captcha->setBackgroundColor($this->backgroundColor[0], $this->backgroundColor[1], $this->backgroundColor[2]);
88 public function setValue(mixed $newValue): mixed
90 if (is_bool($newValue)) {
91 $this->value = $newValue;
93 $this->value = $newValue;
120 if (!$this->validated) {
121 $this->validated =
true;
123 $this->valid = $this->value ===
true || $this->
testPhrase($this->value);
136 $this->captcha->setPhrase($this->sessionSlot[
'formCaptcha'] ??
"");
138 if (!$this->captcha->testPhrase(
$value)) {
153 $phraseBuilder =
new PhraseBuilder();
154 $phrase = $phraseBuilder->build();
156 $this->captcha->setPhrase($phrase);
157 $this->sessionSlot[
'formCaptcha'] = $phrase;
167 $type = strtolower($this->type);
170 $label = $this->htmlLabel();
176 if (empty($this->sessionSlot[
'formCaptcha'])) {
180 $this->captcha->build($this->width, $this->height);
182 return "<p {$wrapperAttributes}>"
184 .
"<span class=\"depage-label\">{$label}{$marker}</span>"
185 .
"<span class=\"captcha-img\">"
186 .
"<img src=\"" . $this->captcha->inline() .
"\" />"
188 .
"<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.
validate()
validates boolean input element value
setValue(mixed $newValue)
set the boolean element value
__construct(string $name, array $parameters, object $form)
__construct
__toString()
Renders element to HTML.
setSessionSlot(&$sessionSlot)
setSessionSlot
getNewPhrase()
getNewPhrase
setDefaults()
collects initial values across subclasses.
testPhrase(mixed $value)
testPhrase
htmlInputAttributes()
renders text element specific HTML attributes
htmlList(?array $options=null, array|string|null $value=null)
Renders HTML datalist.