Populate user form using register-plus and cforms II
May 22, 2008 in internet, php, wordpress
One very key feature of the new cforms II wordpress plugin (8.4.2) is its expanded use of custom variables for its form fields. I have found that it is rather easy to add more variables to be used. Simply add them to lib_aux.php in the cforms II directory. Using register-plus, it is possible to save even more information about the user by adding more fields upon registration as a new user. This information is stored in the usermeta table. Using standard Wordpress variables, making the extra information captured with register-plus available to cforms II as custom variables is a snap!
if ( $wp_db_version >= 3440 ) //&& function_exists( ‘wp_get_current_user’ )
$CurrUser = wp_get_current_user();
$CurrUserId = $CurrUser->ID;
$CurrUserMeta = get_userdata($CurrUserId);
$m = str_replace( ‘{Form Name}’, get_option(’cforms’.$no.’_fname’), $m );
$m = str_replace( ‘{Page}’, $page, $m );
$m = str_replace( ‘{Date}’, $date, $m );
$m = str_replace( ‘{Author}’, $find->display_name, $m );
$m = str_replace( ‘{Time}’, $time, $m );
$m = str_replace( ‘{IP}’, cf_getip(), $m );
$m = str_replace( ‘{BLOGNAME}’, get_option(’blogname’), $m );
$m = str_replace( ‘{CurUserID}’, $CurrUser->ID, $m );
$m = str_replace( ‘{CurUserName}’, $CurrUser->display_name, $m );
$m = str_replace( ‘{CurUserEmail}’,$CurrUser->user_email, $m );
//Some more custom variable for use in the form
$m = str_replace( ‘{CurUserFirstName}’, $CurrUserMeta->first_name, $m );
$m = str_replace( ‘{CurUserLastName}’, $CurrUserMeta->last_name, $m );
$m = str_replace( ‘{CurUserDepartment}’,$CurrUserMeta->department, $m );
