guest-entries icon indicating copy to clipboard operation
guest-entries copied to clipboard

Error but still still saving the entry

Open philipboomy opened this issue 4 years ago • 2 comments

Description

I am not sure if this is related to the post request but Im seeing this in the log:

'error' => 'Couldn’t save entry.' 'notice' => 'Entry saved.'

in the

$_SESSION = []

that appears right after the post request data in the web.log

Am I misunderstand something? It shows an error but there are no errors displayed frontend and its also saving the entry which the notice above also says.

Steps to reproduce

  1. Post using Guest Entry plugin
  2. Check log

Additional info

  • Craft version: 3.5.18
  • PHP version: 7.4.14
  • Database driver & version: MySQL 5.7.32
  • Plugins & versions: Guest Entry 2.3.0

philipboomy avatar Jan 30 '21 10:01 philipboomy

The secret here is that -- in order to stop the entry from being saved -- you need to set isInvalid == true, e.g.

        Event::on(
          SaveController::class,
          SaveController::EVENT_BEFORE_SAVE_ENTRY,
          function(SaveEvent $e) {
            // Grab the entry
            $entry = $e->entry;
            // Check reCAPTCHA
            $isValid = GoogleRecaptcha::$plugin->recaptcha->verify();
            if (!$isValid) {
                $e->isValid = false;
                $entry->addError('recaptcha', 'Please, prove you’re not a robot.');
            }
          }
        );

Refer: https://github.com/craftcms/guest-entries/blob/main/src/controllers/SaveController.php#L123

jcdarwin avatar Dec 04 '22 03:12 jcdarwin

Hi, thanks for reaching out. From your description, I’m not 100% sure what you’re trying to achieve, so I’m not sure if there’s a problem here or not. Are you using any events and manipulating/checking the entry before submission, and then the form is submitted even though it shouldn’t be? If that’s the case, then @jcdarwin’s tip might be something you’re after. If it’s something else, please describe what you’re trying to do and what’s not working so I can look into it.

i-just avatar Dec 13 '22 12:12 i-just