Home Forums Add-ons Repeater Field ACF PRO – Repeater field in form GET POST


ACF PRO – Repeater field in form GET POST

  • Hello,

    I wish to use a repeater field in a form and get the values after the submission. I can acess at normal fields but not to repeaters, I don’t find the correct syntaxe, could you help me ?

    Here is my code

    add_action('genesis_entry_content', 'tsm_do_acf_form_content');
    function tsm_do_acf_form_content() {
        $new_ticket = array(
    		'field_groups'       => array('group_5781107cb5e71'), // Create post field group ID(s)
    		'form'               => true,
    		'html_before_fields' => '',
    		'html_after_fields'  => '',
    		'submit_value'       => 'Poster',
    		'updated_message'    => 'Votre ticket a été créé.'
    // Update existing post data
    add_filter('acf/pre_save_post' , 'tsm_do_pre_save_post' );
    function tsm_do_pre_save_post($post_id) {
    	$repeater_field = 'repeater';
    	$repeater_key = $_POST['acf']['field_5781197cd6ebr'];
    	$sub_field_start = 'sub_field';
    	$sub_field_start_key = 'field_5769116be53524';
    	$sub_field_end = 'sub_field';
    	$sub_field_end_key = 'field_5745116be9824';
    	$ticket_date = 'Ticket';
    	if( have_rows($repeater_field, $repeater_key) ):
    		// loop through the rows of data
    		while ( have_rows($repeater_field, $repeater_key) ) : the_row();
    			$ticket_date = 'Ticket 2';
    			// display a sub field value
    			$ticket_date .= '<p> Start date '  . $sub_field_start_key ;
    			$ticket_date .= ' End date '  . $sub_field_end_key . '</p>';
    	else :
    		$ticket_date = "No ticket";

    Its always show “No ticket”

  • Hi @jacquesmivi

    I’m afraid I don’t understand your setup. Could you please tell me what you want to do with the $ticket_date variable?

    Regarding your issue, could you please check the value of the $repeater_key variable? Please keep in mind that the second parameter of the have_rows() function should be the post ID, so it will make more sense if you use it like this:

    if( have_rows($repeater_field, $post_id) ):

    Also, the acf/pre_save_post is executed before any saving process. If you need to do it after the data is saved, you need to use the acf/save_post hook with a priority of 20 instead. This page should give you more idea about it:

    I hope this makes sense 🙂

  • Thanks for your answer.

    I have a form to pick one or * dates (repeater field), and i wish to send this by email.
    So I try to construct ‘$ticket_date’ with the different walues.

    If I send “$_POST[‘acf’][‘field_5781107cd6eaa’]” I just have “Array” in my email.
    If I send have_rows($_POST[‘acf’][‘field_5781107cd6eaa’]) I got nothing in my email.

  • Hi @jacquesmivi

    That’s because the repeater is posted as an array. If you want to see the values of the array, please try this code:

    $ticket_date = print_r($_POST['acf']['field_5781107cd6eaa'], true);

    To learn how to use an array, please take a look at this page:

    Please check this page to learn how to use a repeater field:

    I hope this helps 🙂

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

The topic ‘ACF PRO – Repeater field in form GET POST’ is closed to new replies.