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.

Store Values in wp_rg_lead_details in hidden fields

  1. Hello all!

    I've been at this for more than an hour, and I think I'm obviously doing something silly.

    Context: I have a volunteer sign up form where users fill out a pretty extensive amount of data. Once they have filled that out, the slightly imperfect solution I've come up with is to have them sign up for an event with their email address, and then have a pre-submission hook in functions.php use $wpdb to pull data for that one form_id, run through each row of data to see if the field_number is equal to my email field in the long form, then check for a matching email. If the email matches, then use the lead_id to pull the name and phone number for follow up.

    I know I can set my hidden fields to strings, as that was the first test I did prior to starting database queries. The problem is using get_results to pull all the data, I'm getting blank values in my "Entries" for the form.

    Can anybody help me see where I've gone astray?

    Function:

    <?php
    
    add_action("gform_pre_submission_9", "volunteer_registration_pre_submission_handler");
    function volunteer_registration_pre_submission_handler($form){
    
    	global $wpdb; 
    
    	$wpdb->rg_lead_detail = $wpdb->prefix . 'rg_lead_detail';
    
    	$email = $_POST["input_1"];
    	$lead_id = "";
    
    	$data = $wpdb->get_results("SELECT lead_id, field_number, value FROM $wpdb->wp_rg_lead_detail WHERE form_id = '1'");
    
    	foreach($data as $data_row) {
    
    		if($data_row->field_number == "3") {
    			if($email == $data_row->value)
    				$_POST["input_4"] = "The emails match";
    			else
    				$_POST["input_4"] = "There is no match";
    			}
    		else
    			$_POST["input_4"] = "There are no field_numbers = 3";
    
    	}
    
    	//Store Data in form's hidden fields
    
    	//$_POST["input_4"] = $lead->lead_id;
    	$_POST["input_3"] = $name;
    }
    ?>
    Posted 13 years ago on Friday December 9, 2011 | Permalink
  2. Hi cdatwood,

    A couple questions for you:

    1. Is the form with the exhaustive amount of information and the form that the user fills out to signup for an event two separate forms?
    2. Assuming that they are two separate forms, is the submitter registered as a user when the first form is submitted? If not, this would make things much simpler for you as you could retrieve the desired information from the user rather than trying to procure it from the database directly.
    Posted 13 years ago on Friday December 9, 2011 | Permalink
  3. Hi David! Thanks for the questions.

    1) Yes, they are two separate forms. One is a multi-step form in GravityForms where email address must be unique in the lead database, and the other is a much simpler form asking for a user's email address, populating the event name from a $_POST variable and hypothetically the rest from the wp_rg_lead_details table where the user's information already resides.

    2) I'm trying to avoid having the user register an account directly within Wordpress (that may be a poor school of thought, but in my mind, I want to keep the users in there limited to staff for the organization).

    The flow I'm trying to achieve is fill out this incredibly long form with all information necessary for our volunteer records, and then to sign up for an event, just enter your email address and the form's hidden data is automatically populated with the event / position being volunteered for, and some information on how to contact the user. In order to increase volunteer conversions for sign up, I want to have them enter as little duplicate information as possible (in the long form they already enter their email, phone number, name, etc.).

    Hopefully that helps! I'm sure I'm just doing something silly with my markup that's causing some kind of mayhem — my biggest problem is that since the function is in functions.php, I'm not sure how to get output without storing information directly to the form and submitting it dozens of time.

    Posted 13 years ago on Sunday December 11, 2011 | Permalink
  4. Hi cdatwood,

    I'd really recommend using the Gravity Form User Registration Add-on to map the data to the user's meta. I wouldn't be too concerned with having different types of WP users. It's made to handle it and there are plenty of plugins out there that will help you keep different administrative capabilities locked down (ie Members).

    Assuming you decide to go the user registration route, you can set your form to only display if the user is logged in. Then you can use this snippet to populate any field with the logged in user's meta via GF dynamic population:

    http://www.gravityhelp.com/forums/topic/right-parameter-names-to-pre-populate-the-names-fields#post-14044

    Let me know if this makes sense. :)

    Posted 13 years ago on Tuesday December 13, 2011 | Permalink
  5. Hi all! I wanted to just post the function I ended up with, that does the trick! Hopefully somebody else can find value in what I hobbled together.

    http://pastebin.com/tX97a4pL

    Posted 13 years ago on Tuesday December 20, 2011 | Permalink
  6. Thank you for posting your code cdatwood.

    Posted 13 years ago on Tuesday December 20, 2011 | Permalink

This topic has been resolved and has been closed to new replies.