Home Forums Front-end Issues My frontend form is prefilled with previous entries all the time


My frontend form is prefilled with previous entries all the time

  • Hi Elliot,

    First of all ACF is a nice plugin to create frontend forms.

    I have some questions on using ACF forms in frontend of wordpress. I have a custom post type named report. I created an ACF field group named report and assigned to my custom post type report.

    I got the code to place the custom report form on frontend and it looks like

    $options = array(
    ‘post_id’ => ‘new’, // post id to get field groups from and save data to
    ‘field_groups’ => array(378), // this will find the field groups for this post (post ID’s of the acf post objects)
    ‘form’ => true, // set this to false to prevent the <form> tag from being created
    ‘form_attributes’ => array( // attributes will be added to the form element
    ‘id’ => ‘post’,
    ‘class’ => ”,
    ‘action’ => ”,
    ‘method’ => ‘post’,
    ‘return’ => add_query_arg( ‘updated’, ‘true’, “?p=”.$_GET[‘p’].”&ptype=report” ), // return url
    ‘html_before_fields’ => ”, // html inside form before fields
    ‘html_after_fields’ => ”, // html inside form after fields
    ‘submit_value’ => ‘Subscribe’, // value for submit field
    ‘updated_message’ => ‘Thank you for the subscription.’, // default updated message. Can be false to show no message

    acf_form( $options );

    And in functions.php of my theme i just put the submit handler

    //create a new report subscription
    function report_pre_save_post( $post_id )
    // check if this is to be a new post
    if( $post_id != ‘new’ )
    return $post_id;

    // Create a new post
    $post = array(
    ‘post_status’ => ‘draft’ ,
    ‘post_title’ => ‘New Subscription’ ,
    ‘post_type’ => ‘acme_thereport’ ,

    // insert the post
    $post_id = wp_insert_post( $post );

    // update $_POST[‘return’]
    $_POST[‘return’] = add_query_arg( array(‘post_id’ => $post_id), $_POST[‘return’] );

    // return the new ID
    return $post_id;

    add_filter(‘acf/pre_save_post’ , ‘report_pre_save_post’ );

    The problem is when i open the form from frontend it is always pre filled with previous entries and i don’t know how to fix that.

    And if i use multiple field groups (forms) like one for subscription , another for event registration within the website then how do i write the submit handler in functions.php.

    Still didn’t get an idea on how the submission process is linked to filter..

    add_filter(‘acf/pre_save_post’ , ‘report_pre_save_post’ );

    We are not explicitly specifying the function to be called on submission. So how do i add multiple forms to the website and include multiple handlers for each form.

    Hope you will provide a nice solution to my problem.

    Many Thanks
    Naveen T

  • Hi @naveen009

    Thanks for the questions:

    auto populate
    This is either 1 of 2 issues:
    1. Check your database post_meta table for values which have an option_name starting with “new_”. Are there any?
    2. Try editing the acf_form function and simply adding a ‘autocomplete=”false” attribute to the form element’

    multiple pre_save_post
    The trick here is to use the ‘html_after_fields’ arg to add in a hidden input with a custom value. This will get posted to the save action which you can then use to determine which form has been posted.

    Hope hat helps.


  • Hi Elliot,

    Thanks for the solution.

    The pre filled form issue is solved.

    Also is there a way to get the name of custom form fields from the pre_save_function.I can see that $fields[‘fields’][‘field_52859d35102ef’] will give the value of a form field but if we have a better method like get_value(“first_name”) it will be better. I mean is there a possibility to get field value directly using field names (like first_name added from administration).


  • Hi! Do you mind explaining how you solved the prefilled form issue? Were you able to use ‘autocomplete=”false”? If so, where did you put that?

    Thanks for the help.

    P.S. I love this plugin! It’s amazing!

  • @naveen009 @Elliot I did below, but still auto populate?

    'post_id' => "new", 
    'field_groups' => array(1677), 
    'submit_value' => "Versturen en nog één toevoegen", 
    'updated_message' => false, 
    'form' => true, 
    'form_attributes' => array('autocomplete' => "off"),

    The form element has the autocomplete = “off”…

    <form id="post" class="acf-form" action="" method="post" autocomplete="off">

    UPDATE: For some reason I interupted the procedure of acf_form to save a post. I think this inserted some values in the DB which caused the problems in all my ACF forms. I deleted the DB and put an old DB from yesterday back and problems solved. Still need to find a way how to solve this now:

  • After hours of debugging, I came across this post. I was having some select fields preloaded (only select fields and some of them). Turns out, I had the new_ fields in my wp_options table.

    Why and how do they generate ? how can I prevent this from happening again ?


  • I’m running into this too, only I can’t find any fields starting with new_ and I’ve turned autocomplete to off.

  • I had the same problem that my form was always populated with values from the last input.

    If the above solutions did not help, here is my solution:

    After importing the field group on a new website I unfortunately left the post type ‘page’ under the position rules. So after each saving of the form all form fields were saved in the metas of the page containing the form. These were then prefilled in the form…
    After I edited the position rules of the field group and after I deleted the page and put it back up again, everything worked fine again.

    Hope this helps someone.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘My frontend form is prefilled with previous entries all the time’ is closed to new replies.