Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error but still still saving the entry #64

Open
philipboomy opened this issue Jan 30, 2021 · 2 comments
Open

Error but still still saving the entry #64

philipboomy opened this issue Jan 30, 2021 · 2 comments
Assignees
Labels

Comments

@philipboomy
Copy link

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
@jcdarwin
Copy link

jcdarwin commented Dec 4, 2022

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

@i-just
Copy link
Contributor

i-just commented Dec 13, 2022

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 i-just self-assigned this Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants