craftcms/guest-entries

Clarify validation (entry model vs content model)

timkelty opened this issue · 2 comments

The README states:

If there is a validation error on the entry, then the page will be reloaded with an entry variable available to it

However, (at least in v1), actually only the element's content is validated, not the entry model itself. I was adding errors to the entry thinking it would stop submission, but since it only validates the content, it doesn't.

v1 example of adding captcha validation:

public function guestEntriesBeforeSaveHandler(GuestEntriesEvent $event)
{
    $entry = $event->params['entry'];
    $verified = craft()->custom_helper->verifyCaptcha();

    if (!$verified) {
        $element->addError('recaptcha', 'There was a problem with the captcha.');

        // We also need this, because only $element->content is validated, not $element.
        $event->isValid = false;
    }
}

Is the same true in v2? If so maybe just a note in the README clarifying that only the content is validated, not the entire entry.

Yeah in v3 the entire entry gets validated (assuming you’ve enabled the “Validate?” setting for the section). Just updated the v2 readme.

Great, thanks!