Hi guys in acf_form add this arguments line:
'html_after_fields' => '<input type="text" id="honeypot" name="honeypot" autocomplete="off">',
in my file functions.php, this code:
// CHECK PRE SAVE POST ACF
function honeypot( $post_id ) {
if($_POST['honeypot'] != ''){
die("You spammer!");
}
}
add_filter('acf/pre_save_post' , 'honeypot', 10, 1 );
in my css style:
#honeypot {display:none;}
The spam control works, but also creates entry in db with empty values. Can you help me fix this code?
I do not want the creation of a voice if it is spam
Thank you very much,
Davide
Hi @sododesign
Could you please tell in which table did the entry created? I’ve just tested it, but I couldn’t find the empty entry you said.
Also, could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Fifteen) with other plugins deactivated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.
Thanks!
I created custom post type ‘RSVP’
it works all right, no problem. The system includes a form via frontend with the function acf_form for confirmation from the guests who will be attending the wedding. Since ACF has captcha default (and I do not really like) I wanted to integrate the technique honeypot to prevent spam as possible. Or add a blank field to my form, and snap the mistake of spam in this case is filled by a bot.
I can block the sending of the form, but also creates an entry in the db with the title and empty fields.
From what I understand, the data that are entered are ignored (in fact, all the fields are empty acf) but I do not want that item is created. Why is spam! I will not fill the db RSVP empty.
I do not think the problem is the theme or plugin, as plugin (except ACF) I have not, and the subject does not create conflicts (the custom made).
I think the error is in the use of as healthy control spam in my functions.php file
My file template for acf_form is this:
acf_form(array(
'post_id' => 'new_post',
'field_groups' => array(
'group_56ab8c95249f9'
),
'new_post' => array(
'post_type' => 'rsvp',
'post_status' => 'pending'
),
'html_after_fields' => '<input class="form-control col-xs-12 guest_user_form" tabindex="-1" type="text" id="guest_user" name="guest_user_rsvp" autocomplete="off">',
'fields' => array(
'field_56ab8cbab11f5',
'field_56ad313d73887',
'field_56ad0de452c1c',
'field_56ad06220e59f',
'field_56ad1215d1217',
'field_56ad2e342039d',
'field_56ad34274f7ee',
'field_56ad34a34f7f0',
'field_56ad34ce4f7f1'
),
'return' => '#rsvp_success',
'field_el' => 'div',
'uploader' => 'basic',
'submit_value' => __('SUBMIT','italian-wedding-day'),
));
my functions.php
// CHECK PRE SAVE POST ACF
function honeypot( $post_id ) {
if(!empty($_POST['guest_user_rsvp'])){
die("You spammer!");
}
}
add_filter('acf/pre_save_post' , 'honeypot', 10, 1 );
or tried to use even the action pre_save but my proble persists
// CHECK PRE SAVE POST ACF
function honeypot( $post_id ) {
if(!empty($_POST['guest_user_rsvp'])){
die("You spammer!");
}
}
add_action('acf/save_post' , 'honeypot', 1 );
Thanks, elliot added honeypot validation. I will be available to all in the next release.
The topic ‘Problem with acf_form’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.