Blog Sections Open
Adding a Simple Captcha Validator to FormIt
When a site needs something lighter than a full external captcha service, FormIt can handle a small custom validator just fine. The legacy example behind this post generated two random digits, displayed them as a tiny ar
When a site needs something lighter than a full external captcha service, FormIt can handle a small custom validator just fine. The legacy example behind this post generated two random digits, displayed them as a tiny arithmetic challenge, and checked the result through a validator.
Generator Snippet
<?php
for ($i = 1; $i <= 2; $i++) {
$r = rand(0, 9);
$rnd .= $r;
$rndsum += $r;
}
$_SESSION['captcha'] = $rndsum;
return '<div class="captcha-img">' . $rnd[1] . '+' . $rnd[2] . '</div>';
Validator
<?php
$success = $value == $_SESSION['captcha'];
if (!$success) {
$validator->addError($key, 'Captcha value is incorrect.');
}
return $success;
FormIt Call
&validate=`captcha:checkCaptcha`
&customValidators=`checkCaptcha`
The lesson is not that every project should build its own captcha. It is that FormIt gives enough control to build lightweight validation flows when the project does not need a heavier third-party solution.
Using includeDocs Correctly in Wayfinder
How includeDocs behaves in Wayfinder and why a manually included resource can still appear outside the branch you expected.
Building MultiPhotos Galleries in Evolution CMS
A practical introduction to using a MultiPhotos-style TV for gallery output in Evolution CMS projects.