Dynamic maxItems in Repeater function

Hi everyone,
I’m using the repeater beta code. It works well.
But I would like to change that maxItems parameter dynamically.
I want the user to enter the number of members in an already-created field.
Then I want to get this variable & put it in my repeater function.
I tried to get that value with get_field_value but it crashes.
Thanks for the help !

Can you share your code William?

<div class="bloc-2-3 poupipo">
  	<h1 class="<?=$back;?>"><?php the_title(); ?></h1>
  	<?php 
  			$id = get_the_ID();
  			$events = new WP_Query( array(
  			'post_type' => 'evenements',
  			'p' => $id
  			));  
  		while ($events->have_posts()) : $events->the_post(); 
  		$rel = get_field('ratach', $events->ID);
  			if($rel):
  			global $post;
  				foreach( $rel as $post ): 
  				setup_postdata( $post );	
  				the_post_thumbnail(); 
  				endforeach; 
  			endif; 
  		endwhile; wp_reset_postdata();
  		global $post;
            $act = $post->post_name;
  		$deb = get_field('date_debut');				
  		$debExp = explode(" ",$deb);
  		$rouh = explode(":",$debExp[3]);
  		$tada = $debExp[0]." ".$debExp[1]." ".$debExp[2];
  		$one= "Le ".$tada." à ".$rouh[0]."h".$rouh[1];
  		$bn = 15;
  		$search_criteria = array(
  			'field_filters' => array(
  				array(
  					'key'   => '12', 
  					'value' => $id
  				)
  			)
  			);
  		$entry_count = GFAPI::count_entries(16, $search_criteria);
  		$entries = GFAPI::get_entries(16,$search_criteria);
  		$j=0;
  		$array=array();
  		$soft = $bn-$entry_count;
  		while($j<$entry_count){
  			$array[]=$entries[$j][14];
  			$j++;
  		}
  		$sum= array_sum($array);?>
  	<p class="emit"><?= $one;?></p>
  	<?php if($sum == $bn && $sum != 0):?>
  	<p class="desole">Désolé, cet événement est complet :(</p>
  	<?php else:;
  	$newSum = $bn-$sum;
  			if(($newSum) == 1):?>
  	<p><strong>Il reste 1 place disponible.</strong></p>
  	<?php else:;?>
  	<p>Il reste <?= $newSum;?> places disponibles.</p>
  	<?php endif;?>
  	<p><span class="req">*</span>Tous les champs sont obligatoires.</p>
  		<?= do_shortcode("[gravityform id='16' field_values='puppy=$act&didi=$id&tada=$tada&toto=$newSum' title='false' description='false' tabindex='49' ]"); ?>
  	<?php endif;?>
  </div>

functions.php :

add_filter( 'gform_form_post_get_meta_16', 'add_my_field' );

function add_my_field( $form ) {

    // Create a Single Line text field for the team member's name

    $name = GF_Fields::create( array(

        'type'   => 'name',

        'id'     => 1002, // The Field ID must be unique on the form

        'formId' => $form['id'],

        'label'  => 'Nom du participant',

        'pageNumber'  => 1, // Ensure this is correct

    ) );

 

    // Create an email field for the team member's email address

    $email = GF_Fields::create( array(

        'type'   => 'email',

        'id'     => 1001, // The Field ID must be unique on the form

        'formId' => $form['id'],

        'label'  => 'Email',

        'pageNumber'  => 1, // Ensure this is correct

    ) );

 

    // Create a repeater for the team members and add the name and email fields as the fields to display inside the repeater.

    $team = GF_Fields::create( array(

        'type'             => 'repeater',

        // 'description'      => 'Maximum of 3 team members  - set by the maxItems property',

        'id'               => 1000, // The Field ID must be unique on the form

        'formId'           => $form['id'],

        'label'            => 'Inscrivez les coordonnées des autres participants',

        'addButtonText'    => 'Valider ce participant', // Optional

        'removeButtonText' => 'Supprimer ce participant', // Optional

        'maxItems'         => $max, // Optional

        'pageNumber'       => 1, // Ensure this is correct

        'fields'           => array( $name, $email ), // Add the fields here.

    ) );

 

    $form['fields'][] = $team;

 

    return $form;

}