I have one of those "tell-a-friend" kind of forms and I want to default the sender's name and email address with the information stored in their Wordpress profile. I got it working, but it seems like a lot of extra coding when I use one filter/function per field like this:
Here's how I pre-populate the sender's name:
add_filter("gform_field_value_f2_fname", "f2_fname");
function f2_fname() {
global $current_user;
get_currentuserinfo();
return $current_user->user_firstname;
}
add_filter("gform_field_value_f2_lname", "f2_lname");
function f2_lname() {
global $current_user;
get_currentuserinfo();
return $current_user->user_lastname;
}
When you have multiple forms with the same field parameter names (i.e. fname and lname), I would think that the system would get confused because it wouldn't know which form you are referencing.
My workaround for this was to pre-pend each parameter name in the form with "f1" for form #1 or "f2" for form #2. Thus, "f2_fname" refers to the "f2_fname" parameter in form #2.
How can I code the function so that each one lumps all the fields into one function? Perhaps like this:
add_filter("gform_????", "default_the_fields_on_form_2");
function default_the_fields_on_form_2($form) {
global $current_user;
get_currentuserinfo();
$fname=$current_user->user_firstname;
$lname=$current_user->user_lastname;
}
Thanks,
Jeff