How do you validate the new Google reCaptcha using volt and phalcon techniques?
(Just wanted to share what I did to make it work, see answer below, hope it helps...)
How do you validate the new Google reCaptcha using volt and phalcon techniques?
(Just wanted to share what I did to make it work, see answer below, hope it helps...)
What you will need
Form
implementationController
implementation (actually no changes needed here, but for completeness...)View
implementationThe Validator
The validator is the most crucial part of this, all other things are rather intuitive ...
Form (class) implementation
Controller implementation
Even though the controller is the same as with every other form, for completeness sake here an example...
View implementation
For the view you can either just put the html there or let it be rendered by the engine. If you want it rendered instead (with e.g.
{{ form.render('recaptcha') }}
), you will have to also create anRecaptcha
Element instead of using one of the defaults (see last point in this answer for that).If you don't wanna use a config for your public key (next section), just set the value of the data-sitekey to your personal (Google reCaptcha) public key.
Also don't forget to include the script (
<script src='https://www.google.com/recaptcha/api.js'></script>
) somewhere (e.g. in your html head section).(Optional) Config
If you wanna use the config to store your recaptcha keys, also add the following to your
config/config.php
...To be able to access the config in your view, you might also need to add
$di->set('config', $config);
to your dependency injector (typically withinconfig/services.php
).(Optional) Recaptcha Element
If you want your recaptcha to be rendered for you (instead of you putting the
div
directly in the view), you will need a separate\Phalcon\Forms\Element\
...You will also have to change your
Form
accordingly:And finally also your
View
: