1

I've created a plugin that will check for a unique email address in the submissions of Freeform. Because I don't want this check to be done with Ajax, I use the Freeform hook 'onBeforeSave'.

Whenever a email is already used, I want the user to know. I'm telling Freeforms that the form is not valid:

craft()->on(
    "freeform_submissions.onBeforeSave",
    function (Event $event) {

        // Let Freeform know the form is not valid
        $event->performAction = false;
    }
);

Unfortunately I haven't found a way to communicate this to the frontend. It would be nice if I could set a Freeform error message.

Any solutions?

1

I've contacted Freeforms (Solspace). Unfortunately there is no solution for this problem (yet). Solspace told me:

This functionality currently isn't possible with Freeform. It's something on our feature requests list though.

0

Never used Freeform before, but it looks like that event has a model param passed into it.

You should be able to add errors to it like any other models in Craft.

craft()->on(
    "freeform_submissions.onBeforeSave",
    function (Event $event) {

        // Let Freeform know the form is not valid
        $event->performAction = false;

        $event->params['model']->addError('email', 'This email is already in use!');
    }
);

This assumes that there is an 'email' attribute on the Freeform_SubmissionModel class and there is logic to display errors in your template similar to: https://craftcms.com/docs/templating/entry-form

1
  • Unfortunately this won't work. – Mr. Sam Nov 1 '17 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.