Home › Forums › Front-end Issues › 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/',
);
ob_start();
acf_form( $options );
$form = ob_get_contents();
ob_end_clean();
} 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>';
print_r($_POST);
echo '</pre>';
}
add_action( 'woocommerce_account_members_endpoint', 'members_content' );
In page.php I’m calling acf_form_head();
<?php
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();
the_sub_field('employee_name');
endwhile;
}
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?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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.