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.

Interpreting a posted field value for use in a document

  1. Hi guys,

    I've been searching through the forum posts and small snippets here and there somewhat guide me to my goal. However, I'm still not there. I hope (one of) you can give me the remaining piece of info to complete my task.

    People filling out my form have to select a radiobutton in order to choose "Yes" or "No". The value selected is translated by using "show values" to 1 (for yes) or 0 (for no). I need this translation, because our automated CSV-import can only interpret a boolean value.

    So far so good. The challenge starts when I want to represent the choice in a resulting (PDF) document in a nice "human" way.

    Proposed solution
    I've added a second field, which is hidden to the public. Using a "hook" I've included a piece of code to the functions.php;

    add_filter('gform_field_value_newsletter', 'my_custom_population_function');
    function my_custom_population_function($value){
    	global $post;
    	$newsletter = get_post_meta($post->ID,'Receive_newsletter');
    	$value='would like';
    	if($newsletter == '0')
    		$value='would not like';
        	return $newsletter;

    The idea is to take the resulting fieldcode of newsletter and integrate it into a sentence, like;

    "I would like to receive a newsletter", or
    "I would not like to receive a newsletter"

    My approach is faulty. I'm trying to set a value based upon a post value, that hasn't been posted yet (right?). Processing of this value can easily take place after post. However, I don't know where to put the code and what code to include.

    Hope my question makes sense? I really like GF and the possibilities seem endless. Unfortunately I sometimes get lost searching for the proper way to proceed.


    Posted 9 years ago on Monday July 23, 2012 | Permalink
  2. When does the automatic CSV import happen? And when does the PDF get created? Since you are going to need some code, can the code which creates the PDF be modified to say "if the value of this field is 0, then say "no newsletter" otherwise say "wants newsletter"? Or do you not have control over that process?

    And I'm not sure how the WordPress post is involved. Is it the entries that are being exported? If so, why do the post and post_meta matter? We need to know if you are using the values in the post or the values in the entry to create your PDF, and how the CSV import is involved with the posts, if it is. Thanks.

    Posted 9 years ago on Monday July 23, 2012 | Permalink
  3. Thanks for your reply, Chris.

    I understand where you are getting at. The order of PDF- and CSV-creation is important. I've been investigating the code and noticed that CSV's are created first. After CSV creation I might be able to interpret the value of the $_POST into a "human text". If I set this value back to the original $_POST it should be integrated correctly. For this I will need to edit the gravity-pdf.php file.

    Thanks for pointing out the route. I will follow and report back the result.


    Posted 9 years ago on Tuesday July 24, 2012 | Permalink
  4. OK, please let us know what you come up with after a little more thought. Thank you.

    Posted 9 years ago on Tuesday July 24, 2012 | Permalink