Hello all :) The more I use Gravity Forms, the more I'm impressed with it.
So I have yet another question. Using this tutorial I've managed to pre-populate a form field with custom data enteres in a logged-in users' profile. (Basically, I created some extra user meta fields, and had them popped into the profile, and created a dropdown of choices in a form based on what the logged-in user has in those fields. In this case, it's different addresses. So if the user is logged in, the addresses in his profile are set as the options in the dropdown.)
Now my question is this: can you create a form with options, and - using information placed in the usermeta - decide if those options are selected by default? the current code I'm using simply rewrites the entire options list, but I dont' want to do that. I just want to change the default selected item to whatever is set in the user's profile (if anything) - and revert to gravity Forms' selected default option if nothing is in t users profile.
Wow, I hope that make sense.
As an example, this is the code where I'm pulling data from the profile to create a dropdown list of addresses:
add_filter('gform_pre_render_32', 'populate_delivery_address_options');
function populate_delivery_address_options($form) {
foreach($form['fields'] as &$field) {
if($field['type'] != 'select' || strpos($field['cssClass'], 'delivery_options') === false) continue;
$shipping = shipping_array();
$choices = array(array('text' => 'Please Choose an Address', 'value' => ' ') );
foreach($shipping as $name => $address) {
$choices[] = array('text' => $name . ': ' . $address, 'value' => $name . ': ' . $address);
}
$field['choices'] = $choices;
}
return $form;
}
I suspect what I'm looking for is set in the $choices variable, but what I want to do is 1) grab the choices set in Gravity Forms form; 2) compare those choices against what's in the user's data; and 3) set one of the Gravity Form options as "selected" based on what's in the user's data.
Is this possible, and if so, how would I do that?