• Resolved PaulH

    (@paulhuckstepp)


    Hi, Great plugin.

    I was wondering if it is possible using a hook to prevent the creation of an entry under certain conditions.

    I’m putting together a custom spam filter using your plugins filters which is working great to prevent an email from being sent, but I’d like to also prevent the creation of the entry in the database table as well, if possible.

    I’ve tried using the add_action af/form/entry_created but the action is never called, possibly because it’s too late in the process via (af/form/submission).

    Is there another way of doing this in the free version of your plugin?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi, Paul! I’m glad you like AF.

    There is no such filter at the moment but I’d be happy to add it. Would something like af/form/entry/should_create which you can return false from work?

    Thread Starter PaulH

    (@paulhuckstepp)

    That would be perfect. Thanks.

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Great! I’ve added this now, available if you grab the latest version from Github: https://github.com/advancedforms/advanced-forms/commit/3bf01af376042b3bf18d7a3deb70a2bfde45da52. Will be included in the next release also of course ??

    Thread Starter PaulH

    (@paulhuckstepp)

    Can this be set during the af/form/submission action?

    add_filter( 'af/form/entry/should_create', function($should_create, $form, $args){return false;},10,3);

    • This reply was modified 2 years, 7 months ago by PaulH.
    Plugin Author fabianlindfors

    (@fabianlindfors)

    Theoretically yes with the right priority but I would recommend adding the logic directly to the filter instead! Does that work in your case?

    Thread Starter PaulH

    (@paulhuckstepp)

    Unfortunately not.

    I use the af/form/submission action to process all the fields in a form and use that information to work out whether to class the submission as spam or not.

    Once all the checks have been made I use the af/form/email/recipient filter to change the recipient to empty to prevent an email from sending.

    I then wanted to add in the new filter af/form/entry/should_create to stop the entry from being created.

    I tested it but the should_create filter didn’t run at this stage.

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Entry creation runs very early, at priority 1, so you’ll need your af/form/submission action to run at a lower priority than that.

    If you are using the af/form/submission/key=FORM_KEY action though, this won’t work as that will always run after the other one. But as the recipient thing works, I don’t think you’re doing that!

    Thread Starter PaulH

    (@paulhuckstepp)

    I use the general ‘all forms’ version of the action. I’ve changed the priority of my action function to -1 and it is now working as I need it to.

    Thanks for the help.

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Great! Glad I could help ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Filter to prevent entry creation’ is closed to new replies.