Support

Account

Home Forums Front-end Issues Get a field value before Save

Solved

Get a field value before Save

  • Hello,

    I would like to be able to read a field value before saving the form to apply it in another field in an acf_form

    I have a “starting_date” date field and an “ending_date” date field for events.
    In case “ending_date” is emplty, I would like to copy “starting_date” value in “ending_date” field.

    I’m pretty sure I’ll get a solution with an “update_value” filter function. I can set a value to a field, but I didn’t found any solution in documentation to get a field value before saving in a acf_form.

    Do you have any clue by chance ?

    Frédéric

  • it was easy in fact, even if getting field value is easier after the save of the post 🙂

    function argu19_set_ending_date_if_empty( $post_id ) {
    	if ( !isset($_POST['acf']['field_5bd0266e9f955']) ) :
    		$value = get_field('event_startingdate');
    		update_field('event_endingdate', $value);
    	endif;
    }
    // Apply to all fields.
    add_filter('acf/save_post', 'argu19_set_ending_date_if_empty', 10, 3);
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.