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.

Assigning hidden values from template

  1. trevor
    Member

    I want to assign a different ebook title to different post pages. I am trying to set $field_data when I call the form, but it is not getting set. I have tried calling the form two different ways...

    First by assigning array values to $field_values when I call the form.
    gravity_form(1, false, true, $field_values = array( "ebook-title" => $ebooktitle, "Phone" => "(907)555-1234" ), '', false)

    Second by assigning the array to a variable then using the variable to set $field_values.

    $tpd_field_values_set = array( "ebook-title" => $ebooktitle, "Phone" => "(907)555-1234" );
    gravity_form(1, false, true, $field_values = $tpd_field_values_set, '', false);

    The form shows up on the page but none of the data is there. I selected "Allow field to be populated dynamically". The variable $ebooktitle is set.

    How do I use data from my post to populate on form when the post loads.

    Thanks for your help
    Trevor

    Posted 13 years ago on Tuesday October 23, 2012 | Permalink
  2. trevor
    Member

    Resolved.

    I finally got the post to auto populate using the gform_pre_render hook.

    add_filter( 'gform_pre_render_1', 'auto_pop_form_function' );
    
    function auto_pop_form_function( $form ){
    
    	global $wp_query;
    	$thePostID = $wp_query->post->ID;
    	$postInfo = get_post_meta( $thePostID, 'custom-post-data', true);
    
    	foreach($form['fields'] as &$field)
    		if($field['id'] == 1){
    			$field['defaultValue'] = $postInfo;
    		}
    		else if ($field["id"] == 4){
    			$field["defaultValue"] = 'hard coded text string';
    		}
    
    	    return $form;
    }

    Using $field['defaultValue'] to set my value will work for my purposes. I am still not sure how to change a field value.

    Posted 13 years ago on Wednesday October 24, 2012 | Permalink