Home Forums Front-end Issues Get $_POST array of acf_form() submit


Get $_POST array of acf_form() submit

  • Hello!

    Thanks for you perfect and flexible plugin.

    I want to know – How I can get $_POST array when user submits acf form with repeater field?

    I have an acf form in user’s profile page and I’m using shortcode to display it.

    That’s shortcode

    function my_acf_user_form_func( $atts ) {
    	$shortcode_attributes = shortcode_atts( array(
    		'field_group' => ''
    	), $atts );
    	$user_id = get_current_user_id();
    	if ( ! empty ( $shortcode_attributes['field_group'] ) && ! empty ( $user_id ) ) {
    		$options = array(
    			'post_id' => 'user_' . $user_id,
    			'field_groups' => array( intval( $shortcode_attributes['field_group'] ) ),
    			'uploader' => 'basic',
    			'return' => '/my-account/members/',
    		acf_form( $options );
    		$form = ob_get_contents();
    	} else {
    		echo 'Please, login to view profile page';
    	return $form;
    add_shortcode( 'my_acf_user_form', 'my_acf_user_form_func' );

    That’s shortcode’s init.

    function members_content() {
    	echo '<h3>Personalization</h3><p>Welcome to the Personalization page. Manage your team members.</p>';
    	echo do_shortcode('[my_acf_user_form field_group="1302"]');
    	echo '<pre>';
    	echo '</pre>';
    add_action( 'woocommerce_account_members_endpoint', 'members_content' );

    In page.php I’m calling acf_form_head();

    get_header(); ?>

    When I try to submit the form all data is saved successfully, but I can’t get data from $_POST var.

    So, I’m tried to call acf/save_post action, but without any luck

    function my_acf_save_post( $post_id ) {
    	echo $post_id;
    	$user_id = get_current_user_id();
    	echo '<h1>Some text</h1>';
    	echo $user_id;
    	while ( have_rows('team_repeater', $user_id) ) : the_row();
    add_action('acf/save_post', 'my_acf_save_post', 20);

    I just want to get each row in repeater field to send all data via API to another app.

    So, please direct me in the right direction, thanks!

    Have a good weekend

  • You cannot get $_POST where you are trying to do it. When the ACF form is submitting, the form is process and then redirected back to the page. This means that when the page reloads $_POST will contain nothing.

    Similarly, you cannot display information during during acf/save_post, once ACF is finished the page is redirected, so if anything is displayed it would be removed when the page reloads.

    You need to use acf/save_post, but you need to do something with the information other than display it. This is where you should be sending the data to the other API instead of trying to display it.

  • Thanks for you response!

    I hope that in your work there was a similar experience of the task.

    Tell me, please, a ready-made solution that takes a value from the repeater fields that users fill out and sends / outputs them?

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

The topic ‘Get $_POST array of acf_form() submit’ is closed to new replies.