balboj,
I filter the data based on the form_id and field_id. Here’s an example of what I’m using. This will grow rather quickly if i keep going this route – this’d be better if they were just parameters in the shortcode, but that’s not implemented:
add_filter( ‘vfb_field_default’, ‘vfb_filter_field_default’, 10, 4 );
function vfb_filter_field_default( $default, $field_type, $field_id, $form_id ){
switch ( $field_type ) :
case ‘name’:
if ( is_user_logged_in() ) :
return vfb_get_name();
endif;
break;
case ’email’:
return vfb_get_email();
// do nothing
break;
endswitch;
switch ( $form_id ):
case 3: // Job Application Form
switch ( $field_id ):
case 41: //Hidden Name field
return vfb_get_name(); // I only allow logged in users access to this form.
break;
endswitch;
break;
case 5: // Test form
switch ( $field_id ):
case 57: // Hidden Name
return vfb_get_name();
break;
case 58: // Hidden Email
return vfb_get_email();
break;
case 59: // Visible Text field
return ‘abcdefg’;
break;
endswitch;
break;
endswitch;
return $default;
}
function vfb_get_name(){
$current_user = wp_get_current_user();
if ( !empty( $current_user->user_firstname ) && empty( $current_user->user_lastname ) )
$first = $current_user->user_firstname;
else if ( empty( $current_user->user_firstname ) && !empty( $current_user->user_lastname ) )
$last = $current_user->user_lastname;
else if ( !empty( $current_user->user_firstname ) && !empty( $current_user->user_lastname ) ) {
$first = $current_user->user_firstname;
$last = $current_user->user_lastname;
}
return “$first $last”;
}
function vfb_get_email(){
if ( is_user_logged_in() ) :
$current_user = wp_get_current_user();
return $current_user->user_email;
endif;
return “”;
}
Hope that helps.