Skip to content

For developers

The module recognizes PrestaShop core forms and the newsletter, product review and availability alert modules by itself. If your module or theme has its own form, you can have it protected by the same mechanism. You need two things: an attribute in the form and one call on the server. Both use the same action name.

<form method="post" action="{$link->getModuleLink('mymodule', 'submit')}" data-mv-captcha="review">
<!-- form fields -->
<button type="submit">Send</button>
</form>

The attribute value is the action name: letters and underscore only, at most 32 characters. Other characters are dropped, an empty value means custom. On submit the module script obtains a token and adds it to the form as the mv_captcha_token field.

It also works for forms submitted without reloading the page (AJAX) if they send the form data. If you build the data yourself, send the mv_captcha_token field with the value from the form.

if (class_exists('MvCaptchaV1') && !MvCaptchaV1::verify('review')) {
$this->errors[] = MvCaptchaV1::errorMessage();
return;
}
// regular form processing
  • MvCaptchaV1::verify($action) returns true if the form may be processed and false if verification failed. The action name must match the one in the form attribute.
  • Call it once per request and before processing, for example before saving or sending an email. A token is valid only once, so a repeated call in the same request returns the same result.
  • MvCaptchaV1::errorMessage() returns the message for the visitor in the shop language, safe for HTML.
  • The class_exists('MvCaptchaV1') check makes sure your module works even when the form protection module is not installed.

The function also returns true when verification is not needed or not available, so your form is never blocked by the module itself:

  • the module is off, has no valid license or has no keys,
  • the customer is logged in and Neoverovať prihlásených zákazníkov (Do not verify logged-in customers) is on,
  • the service is down and Pri výpadku služby formulár odoslať (Submit the form when the service is down) is on.

Attempts from custom forms are counted in the overview in the Formuláre iných modulov (Forms of other modules) row.

Was this article helpful?