PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Populate dynamically when form sent

  1. Dear all,

    I trying to affect a user card member using the biggest value found on the user_meta table sor subscribers. Everythinks is working well, but i have an issue.

    Im changing the value of an hidden field (user_uuid) with a hook, and affect him a value.
    Problem is, two person can be connected at the same time, using the same form, and has the same populated value at the same time.

    Solution should be to affect the value, only when the form is sent.
    Any idea how to make it ?

    My code bellow.

    add_filter('gform_field_value_maxnummembre', 'populate_memberid');
    function populate_memberid($value){
        $args = array(
    	'role' => 'Subscriber',
    );
    
    // The Query
    $user_query = new WP_User_Query( $args );
    
    // User Loop
    if ( !empty( $user_query->results ) ) {
    	foreach ( $user_query->results as $user ) :
    		$uuid = get_user_meta( $user->ID, 'user_uuid', true);
    		echo '<p>' . $user->display_name . ', Membre n° '.$uuid.'</p>';
    		$nummembre[] = $uuid;
    	endforeach;
    
    	$maxnummembre = (max($nummembre) + 1);
    	echo 'Nouveau : '.$maxnummembre;
        return $maxnummembre;
    }
    }
    Posted 8 years ago on Thursday February 28, 2013 | Permalink
  2. Ok. I have modify my code to and use the function gform_pre_submission. But it's seem very slow when i sending a form now. Any Idea ?

    add_action("gform_pre_submission_2", "pre_submission_handler");
    function pre_submission_handler($form){
        $args = array(
    	'role' => 'Subscriber',
    );
    
    // The Query
    $user_query = new WP_User_Query( $args );
    
    // User Loop
    if ( !empty( $user_query->results ) ) {
    	foreach ( $user_query->results as $user ) :
    		$uuid = get_user_meta( $user->ID, 'user_uuid', true);
    		//echo '<p>' . $user->display_name . ', Membre n° '.$uuid.'</p>';
    		$nummembre[] = $uuid;
    	endforeach;
    	$maxnummembre = (max($nummembre) + 1);
    	$_POST["input_14"] = $maxnummembre;
    
    	//echo 'Nouveau : '.$maxnummembre;
        //return $maxnummembre;
    }
    }
    Posted 8 years ago on Thursday February 28, 2013 | Permalink
  3. How many subscribers do you have? If there are a lot, I can see this code being slow since you are going through all your users in the loop.

    Posted 8 years ago on Monday March 4, 2013 | Permalink