PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Prepopulate with user meta does not show in entries

  1. suineg
    Member

    Hi!

    I've searched the forums but cant find anything about this particular thing so here goes..

    I got a pretty complex form which is supposed to pull in data from the currently logged in user and put it into some fields..
    I've tried both this solution :
    http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name

    and using the gform_pre_render_1 hook in order to do this and they both work fine.. The users info is automatically put into the values of the fields..

    however when I then submit the form these values are not passed on to the entry or the email confirmation.. they appear as empty fields.. regardless of which of the two ways to prepopulate Im using!

    I'm really friggin frustrated so now I'm asking for help.. could this be a bug or?

    Here's how the version with the pre_render hook looks like (I put the content into the $field['content'] parameter as well just to try, didnt change anything):

    $user_id = get_current_user_id();
    			$user_fields = get_fields('user_'.$user_id);
    	        if(strpos($field['cssClass'], 'disabled') !== false){
    				if($user_fields){
    					foreach($user_fields as $fieldname => $fieldvalue){
    						$fieldname = str_replace('user_', 'order_', $fieldname);
    						$fieldclass = explode(' ', $field['cssClass']);
    						if($fieldname == $fieldclass[0]){
    							$field['defaultValue'] = $fieldvalue;
    							$field['content'] = $fieldvalue;
    						}
    					}
    				}				
    
    			}

    And heres how the other version look like (with just a sample filter):

    add_filter('gform_field_value_user_business', create_function("", '$value = populate_usermeta(\'user_business\'); return $value;' ));
    function populate_usermeta($meta_key){
    	$user_id = get_current_user_id();
    	$user_fields = get_fields('user_'.$user_id);
    	//return $current_user->__get($meta_key);
    	if($user_fields){
    		foreach($user_fields as $fieldname => $fieldvalue){
    			if($meta_key == $fieldname){
    				return $fieldvalue;
    			}
    		}
    	}
    }

    I'm using Advanced custom fields for creating the user meta but that doesnt really matter since they're just values and that part I know works fine since the output is actually visible on the form frontend.

    And yes, I've set the fields to dynamic population and checked the parameter for that. :)

    Posted 11 years ago on Friday May 24, 2013 | Permalink
  2. Sorry, this post was tagged "Spam" by Akismet. We just recovered the post and made it visible again today (June 3, 2013 3:33PM).

    Posted 11 years ago on Tuesday June 4, 2013 | Permalink
  3. Can you paste all the code you're using, including the filter call, at pastebin.com or pastie.org so we can see it in its entirety?

    Posted 11 years ago on Tuesday June 4, 2013 | Permalink
  4. suineg
    Member

    I've actually been able to narrow it down..

    The reason it wasn't saving the field values was because I'm setting the inputs to disabled="disabled"..

    The reason being that they are automatic fields retrieved from the currently logged in user and I dont want them to be able to change them but at the same time I need the info to be in textinputs for the submission and PDF creation...

    So do you know of any way for me to remove the check gravityforms do to allow for disabled inputs to also pass through submission?

    Posted 11 years ago on Tuesday June 4, 2013 | Permalink
  5. suineg
    Member

    Can I ask you something else now that I've got you..

    I'm trying to change the value chosen from a select field before submission using the gform_pre_submission_filter but the $form object doesn't seem to contain the values? This is the printed array for the select..

    [2] => Array ( [adminLabel] => [adminOnly] => [allowsPrepopulate] => [defaultValue] => [description] => [content] => [cssClass] => user_business [errorMessage] => [id] => 14 [inputName] => [isRequired] => 1 [label] => Företagsnamn: [noDuplicates] => [size] => medium [type] => name [postCustomFieldName] => [displayAllCategories] => [displayCaption] => [displayDescription] => [displayTitle] => [inputType] => [rangeMin] => [rangeMax] => [calendarIconType] => [calendarIconUrl] => [dateType] => [dateFormat] => [phoneFormat] => [addressType] => [defaultCountry] => [defaultProvince] => [defaultState] => [hideAddress2] => [hideCountry] => [hideState] => [inputs] => [nameFormat] => simple [allowedExtensions] => [captchaType] => [pageNumber] => 1 [captchaTheme] => [simpleCaptchaSize] => [simpleCaptchaFontColor] => [simpleCaptchaBackgroundColor] => [failed_validation] => [productField] => [enablePasswordInput] => [maxLength] => [enablePrice] => [basePrice] => [calculationFormula] => [calculationRounding] => [enableCalculation] => [disableQuantity] => [inputMask] => [inputMaskValue] => [formId] => 1 [descriptionPlacement] => below )
    Posted 11 years ago on Tuesday June 4, 2013 | Permalink
  6. At the time of gform_pre_submission, you have access to the $form object for all the values which initially existed when you created the form, and the $_POST, which will contain all the submitted data. You probably want to change the $_POST to change the submitted value. You can see the documentation here: http://www.gravityhelp.com/documentation/page/Gform_pre_submission_filter

    Posted 11 years ago on Monday June 10, 2013 | Permalink