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

FR: Ability to throw HoneyPotException in Form Listener #1165

Closed
edalzell opened this Issue Dec 17, 2016 · 1 comment

Comments

Projects
None yet
3 participants
@edalzell

edalzell commented Dec 17, 2016

I'm creating an Akismet addon and I'd like to act like the Honeypot does in forms, i.e. the form "looks" like it submits successfully (no errors returned) but doesn't.

Expected behaviour

FormListener catches any HoneyPotException thrown by any registered listeners

try{
        // Allow addons to prevent the submission of the form, return
        // their own errors, and modify the submission.
        list($errors, $submission) = $this->runCreatingEvent($submission);

        if ($errors) {
            return $this->formFailure($params, $errors, $formset);
        }

        $submission->save();

        // Emit an event after the submission has been created.
        $this->emitEvent('submission.created', $submission);
} catch (HoneypotException){}

Actual behaviour

Any exception thrown is not trapped by Forms. Instead normal Whoops is seen.

@edalzell

This comment has been minimized.

edalzell commented Dec 17, 2016

I think the whole method could just be:

    public function create()
    {
        $fields = Request::all();

        $params = Crypt::decrypt(Request::input('_params'));
        unset($fields['_params']);
        $formset = array_get($params, 'formset');

        $form = Form::get($formset);

        $submission = $form->createSubmission();

        try {
            $submission->data($fields);
            $submission->uploadFiles();

            // Allow addons to prevent the submission of the form, return
            // their own errors, and modify the submission.
            list($errors, $submission) = $this->runCreatingEvent($submission);

            if ($errors) {
                return $this->formFailure($params, $errors, $formset);
            }

            $submission->save();

            // Emit an event after the submission has been created.
            $this->emitEvent('submission.created', $submission);

        } catch (PublishException $e) {
            return $this->formFailure($params, $e->getErrors(), $formset);
        } catch (HoneypotException $e) {
        }

        return $this->formSuccess($params, $submission);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment