guest-entries
guest-entries copied to clipboard
Error but still still saving the entry
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
- Post using Guest Entry plugin
- 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
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
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.