Home Forums Front-end Issues How do I get the form to save


How do I get the form to save

  • I have added the <?php acf_form_head(); ?> to the page. When I use the `acf_form()’ and save that way it saves.

    However I want to design the form myself and have all the fields outputting and getting the right markup/name/key/id the same as the auto rendered form. I tried and troed and it just won’t save so then I maulaly copued the 2 hidden divs and their hidden fields into my form and bingo! it saved.
    <div id=”acf-form-data” class=”acf-hidden”>
    <input type=”hidden” name=”_acfnonce” value=”52ddba9d81″>
    <input type=”hidden” name=”_acfchanged” value=”0″>

    <div class=”acf-hidden”>

    <input name=”_acf_form” value=”eyJpZIsIm5mYWxzZSwiZmllbGRzIjpmYWx…etc…” type=”hidden”>

    What do they have that allows it to save and how can I get the right info to auto appear in mine. I suspect that if I use this on another form the _act_form value won’t be right or the _acfnonce. Where do they come from and how do i get them?


  • I was missing the _acfnonce. It might be worth updating the development documents to specify this as it’s not anywhere on the net that I could find easily!

    for reference my code was

    $nonce = wp_create_nonce( 'acf_form' );
    $args = wp_parse_args( $args, array(
    		'id'					=> 'acf-form',
    		'post_id'				=> false,
    		'new_post'				=> false,
    		'field_groups'			=> false,
    		'fields'				=> false,
    		'post_title'			=> false,
    		'post_content'			=> false,
    		'form'					=> true,
    		'form_attributes'		=> array(),
    		'return'				=> add_query_arg( 'updated', 'true', $url ),
    		'html_before_fields'	=> '',
    		'html_after_fields'		=> '',
    		'submit_value'			=> __("Update", 'acf'),
    		'updated_message'		=> __("Post updated", 'acf'),
    		'label_placement'		=> 'top',
    		'instruction_placement'	=> 'label',
    		'field_el'				=> 'div'
    <form id="post" class="acf-form" action="" method="post" autocomplete="off" enctype="">
    <input type="hidden" name="_acfnonce" value="<?php echo $nonce; ?>">
    <? acf_hidden_input(array( 'name' => '_acf_form', 'value' => base64_encode(json_encode('$args')) )); ?> of form ...

    I don’t know if there is a shorter way, but this works for now!

  • Oh wait… the _acf_form bit didn’t work

    <? acf_hidden_input(array( ‘name’ => ‘_acf_form’, ‘value’ => base64_encode(json_encode(‘$args’)) )); ?>

    Any ideas please?

  • Just needs ‘post_id’ setting to the post id

    'post_id' => get_the_ID()

    And it works!

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

The topic ‘How do I get the form to save’ is closed to new replies.