Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'gform_pre_render_8', 'graduate_profile_populate' );
- add_filter( 'gform_pre_submission_filter_8', 'graduate_profile_populate' );
- function graduate_profile_populate( $form ) {
- // grab current user's information
- global $current_user;
- get_currentuserinfo();
- $user_login = $current_user->ID;
- // grab all entries from Membership form with #4
- $entries = RGFormsModel::get_leads( 4 );
- // find any submitted entries that belong to this user
- foreach( $entries as $entry ) {
- // $entry["created_by"] stores the Wordpress User ID of the user that submitted the form
- switch( $entry["created_by"] ) {
- case $user_login: // if our "created_by" ID matches our $user_login ID
- $lead_id = $entry["id"]; // store ID of this entry in $lead_id variable
- break;
- default:
- break;
- }
- //echo '<pre>'; print_r($entries); echo '</pre>';
- }
- // if $lead_id exists
- if( $lead_id ) {
- // get entry data by lead ID
- $entry = RGFormsModel::get_lead( $lead_id );
- foreach( $form["fields"] as &$field ) {
- switch( $field['type'] ) {
- case 'name':
- case 'address':
- foreach( $field['inputs'] as &$input ) {
- $field['allowsPrepopulate'] = true;
- $parameter_name = strtolower( str_replace( ' ', '_', str_replace( '/ ', '', $input['label'] ) ) );
- $input['name'] = $parameter_name;
- $input_value = rgar( $entry, ( string ) $input['id'] );
- add_filter( 'gform_field_value_' . $parameter_name, create_function( "", "return '$input_value';" ) );
- }
- break;
- case "day" :
- return array(
- "start_date" => gmdate( "Y-m-d" ),
- "end_date" => gmdate( "Y-m-d" ) );
- break;
- case "week" :
- return array(
- "start_date" => gmdate( "Y-m-d", strtotime( "last Monday" ) ),
- "end_date" => gmdate( "Y-m-d", strtotime( "next Sunday" ) ) );
- break;
- case "month" :
- $month_start = gmdate( "Y-m-1" );
- return array(
- "start_date" => $month_start,
- "end_date" => gmdate( "Y-m-d", strtotime( "{$month_start} +1 month - 1 hour" ) ) );
- break;
- case "year" :
- return array(
- "start_date" => gmdate( "Y-1-1" ),
- "end_date" => gmdate( "Y-12-31" ) );
- break;
- default:
- $field['defaultValue'] = $entry[$field['id']];
- break;
- }
- }
- }
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement