Home Forums Front-end Issues Manually populating field in acf_form


Manually populating field in acf_form

  • Im creating a front-end request form using acf_form which creates a post on submission. The administrator can then go and review the post and approve/reject it.

    Within the post iv set up some acf fields including a user field so that they can see who has created the post/made the request.

    Below is my form at the moment. I know i havent added in the ‘new_post’ bits yet to create the post and the reason for multiple acf_forms is for layout reasons.

    My query is that is there a way to automatically update one of my acf fields? I need the user field to automatically select themself (current user) so when they create the user field has them selected (rather than having to select themself from a list of users). Im sure its simple, but how would i go about this?

    <form id="post" class="acf-form" action="" method="post">
    <?php acf_form(array(
    	'fields' => array('field_59246521cd289'),
    	'form' => false,
    )); ?>
    <?php acf_form(array(
    	'fields' => array('field_5924656acd28a'),
    	'form' => false,
    )); ?>
    <?php acf_form(array(
    	'fields' => array('field_592465a7cd28b'),
    	'form' => false,
    )); ?>
    <div class="acf-form-submit">
    	<input type="submit" class="acf-button button button-primary button-large" value="Submit Request">
    	<span class="acf-spinner"></span>
  • I would not include the user field on the front end form at all, it would be a field that only the site admin could manage on the back end.

    In the pre_save_post filter that you’ll be creating I would get the current user ID and then after adding the post I’d use update_field() to update the user field. Make sure you use the field key when calling update_field() and not the field name for $selector.

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

The topic ‘Manually populating field in acf_form’ is closed to new replies.