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.

Outputting conditional field within content template

  1. Hello, I have searched for a long time to find the answer to this. Essentially, I want to be able to output a conditional field into the content template. I know this is possible, but I need a prefix that will not show when the field is not used.

    let me explain the exact scenario.
    It is a site for listing real estate properties and one field asks the user if they are the homeowner or an agent. If they are an agent, we need their licensing number, which is obtained in the following field. The licensing number needs to be displayed on the post, but I would like to format it so that it can look like this:
    Agent PRC License Number: 123456789

    However, I can only seem to be able to output the field into the content template. I do not want to add "Agent PRC License Number:" in front of the field because if the user is a homeowner, then it would display "Agent PRC License Number:" with no license number.

    Is there a way to do this? Maybe I could add a prefix to the license number field so that it would output the prefix in front of the license number when it is called within the content template?

    Do you have any suggestions?

    Many thanks

    Posted 7 years ago on Tuesday January 17, 2012 | Permalink
  2. Hi, Dave,

    I apologize for the delayed response to your post.

    Since you are using post content templates to format the display, you could create the post content template manually using the hook "gform_pre_submission_filter". This way you can create the content template based on the radio button selection and only include the fields you need for the selection. Below is an example:

    //add filter to form id 23
    add_filter("gform_pre_submission_filter_23", "pre_submission_filter");
    function pre_submission_filter($form)
    	//check value of radio button and build content template
    	if (rgpost("input_8") == "Agent")
    		//put fields used for Agent into postContentTemplate, use "\n" for a carriage return
    		//use merge tags, easiest to build the template in the admin and copy out what you need for the fields
    		$form["postContentTemplate"] = "Agent PRC License Number: {License Number Field 1:10}";
    		//put fields used for Homeowner into postContentTemplate
    		$form["postContentTemplate"] = "This is my template when the user is a Homeowner: {License Number Field 1:10}";
    	//return modified form object, the merge tags will be replaced after this
    	return $form;

    Take a look and let me know if you have questions.

    Posted 7 years ago on Wednesday February 1, 2012 | Permalink

This topic has been resolved and has been closed to new replies.