Support

Account

Home Forums General Issues Image Field to a Post

Solving

Image Field to a Post

  • I wish to create a frontend form that submits images to a post for a competition.

    The images can then all be viewed in a gallery perhaps.

    This is what I want to do, just not sure the best way to do this.

    I have set up a front end form, just not sure how to save this, I don’t want to save each submission as a new post, so how would I save the form submissions to a single post?

  • Hello there,

    Thanks for getting in touch!

    You can assign a particular post id to the form through the ‘post_id’ parameter like so:

    <?php acf_form(array(
    					'post_id'	=> 123,
    					'post_title'	=> false,
    					'submit_value'	=> 'Update the post!'
    				)); ?>

    I hope this info helps. Thank you.

  • Yes I was thinking of doing something like that, however each submission/post of the form, needs to create a new row of fields within the post, and not just update the same each time if that makes sense.

  • Hi @mikey2004

    In this case, you can grab individual field values from the $_POST data like so:
    $field_value_1 = $_POST['acf']['field_xxxxxxxxxxx'];
    In this example, we are making use of field key to target a certain field and you can then add a new row of data to an existing repeater by making use of the following function: https://www.advancedcustomfields.com/resources/add_row/
    I recommend using field keys in the above function since this allows ACF to correctly find the field if no existing value has been saved.

    Thank you.

  • This sounds great, and a good way to do what I want to create.

    How would I combine all this, where would the code about submitting to a new row on a field be added via the form?

  • Hi there,

    You can hook into the acf/save_post hook that is called when the form is submitted and create this logic.
    Please take a look at the examples on this page: https://www.advancedcustomfields.com/resources/acf-save_post/

    I hope this info helps.

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

You must be logged in to reply to this topic.