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.

Use Post/Page Title for Subject

  1. I have searched and I think my option is to use the gform_pre_render, not sure. This is not Gravity Forms problem but I think the work around is to use the gform_pre_render stuff. I have a real estate theme that when a property is viewed, the real estate agents are listed in the sidebar. Under each agent is a contact button that drops down and displays that agent's contact form for that property.

    CForms 7 works fine and populates the title, Gravity populates the Agent's name instead. Gravity will pull the proper URL for the post. I have tried Gravity in the body of a post and it works fine. Obviously it is getting confused and thinks that the agent's name is the post title when it is not.

    Either way, I think that using the gform_pre_render should take care of the issue. Can someone post the proper way to use it to pull the page/post title to be used into a text field?

    Posted 11 years ago on Thursday December 27, 2012 | Permalink
  2. Where are you trying to use the Page or Post title? You said "subject" in the title of this topic, but I can't tell from your request where you're trying to use it. Can you explain how you want to use the Page or Post title in your Gravity Form?

    Posted 11 years ago on Thursday December 27, 2012 | Permalink
  3. However, you can always use a gform_pre_render filter and this WordPress function:

    [php]
    $the_title_is = get_the_title($post->ID);
    Posted 11 years ago on Thursday December 27, 2012 | Permalink
  4. This particular situation, the form is on the sidebar of a page. The subject is nothing more than a text field labeled 'subject' so the email will tell the recipient of the form submission which particular property the form is in reference to. The title of the page should be autofilled into this field.

    I'll try the above and let you know. Thanks!

    Posted 11 years ago on Thursday December 27, 2012 | Permalink
  5. So I would just put this in my theme functions:

    add_filter("gform_pre_render", "set_subject");
    
    function set_subject($form){
    
    	//only populating subject field for form id 3
    	if($form["id"] != 3)
    		return $form;
    
    			$the_title_is = get_the_title($post->ID);
    
    		return $form;
    }

    How would I call it to my text field which is ID3 and is labeled 'Subject'?

    Posted 11 years ago on Thursday December 27, 2012 | Permalink
  6. pasting that code into the functions did not work. I'm obviously doing a lot wrong probably... Can you tell me what I'm doing wrong? thanks!!

    Posted 11 years ago on Friday December 28, 2012 | Permalink
  7. I can get the below example to work ... just so you know. I can't get it to do what i want it to do but I can get the hidden field in the form... now how do I call the page title at the same title?

    add_filter("gform_field_input", "tracker", 10, 5);
    function tracker($input, $field, $value, $lead_id, $form_id)
    {
          //because this will fire for every form/field, only do it when it is the specific form and field
    	if ($form_id == 3 && $field["id"] == 3)
    	{
    		$input = '<input type="hidden" id="hidTracker" name="hidTracker" value="test">';
    		return $input;
    	}
    }
    Posted 11 years ago on Friday December 28, 2012 | Permalink
  8. You can skip most of this. If you just want to use the embedded post title as a text field or the subject line of the email, you can insert this merge tag pretty much anywhere, no code required:

    {embed_post:post_title}
    Posted 11 years ago on Friday December 28, 2012 | Permalink
  9. Maybe I should just give you a link to see what I'm talking about.

    In the sidebar, there are two agents listed, the top one (Tom) is using gforms, the bottom one (Amanda) is using cforms. As you can see the gforms one is pulling in the name of the agent and not the title of the current page, unlike the cforms one. Is this possible to change as I would really like to continue using gforms for all my sites.
    http://www.realestateincentralflorida.com/listing/500-michelle-circle-3/

    Posted 11 years ago on Friday December 28, 2012 | Permalink
  10. I have tried that but it returns the Agent's name and not the page title. Please view the link in my last post and let me know if it's because it's in the sidebar or something?

    Posted 11 years ago on Friday December 28, 2012 | Permalink
  11. I see what you mean with the top form, the Gravity Form. But that is not how Gravity Forms normally works. When a form is embedded in the sidebar, you can still use the merge tag ({embed_post:post_title}) as the default value for the subject line in your form and it will populate the form with the post_title. Is that how you have your form configured: with a default value of this merge tag, as the subject field? Can you post a screenshot of that please?

    Take a look at any property on this site:
    http://www.mainevacationrentalsonline.com/3190/bears-den-in-surry-maine.htm

    If you check the sidebar contact form, it is using the merge tag {embed_post:post_title} as the default value for "Regarding" and the Post title is pre-populated there. Here is a screenshot of the configuration for that field http://minus.com/lbacfbbfGkWQL0

    It's possible your sidebar is added before the post title is determined, or maybe there is something in the theme which is modifying that value somehow. You can test with the default twenty ten or twenty eleven theme to see if this is a theme conflict. It could also be a plugin conflict. You can test for those by following these instructions http://rkt.gs/testing

    Posted 11 years ago on Friday December 28, 2012 | Permalink
  12. Yes I am using the embed code that is builtin. That's what started this whole thing. As you can see on the contact page, the gform and that code is working fine.
    http://www.realestateincentralflorida.com/contact-us/

    i think what you said is correct, it's firing off prematurely or something. The agents, their information and their contact forms are added to the sidebar by the theme and then probably the listing, but how would it know what agents if it doesn't know what listing? :) As I said in the first post, it's not a gforms problem, I was just thinking there was a work around on the gforms side that may allow me to use my gforms on this site because I love gforms. :)

    Screenshot:
    http://www.realestateincentralflorida.com/wp-content/uploads/formissue.jpg

    Posted 11 years ago on Friday December 28, 2012 | Permalink
  13. Funny thing is, I reversed engineered their code a little to find out how they are doing it in the theme, and it looks as though they simply take the default value of the cforms form for that field which is "your-subject" and just replace it with a variable that grabs the page title. I can add "your-subject" to the gforms form and it still brings up the agent's name and not title of the page.

    Their code in the variables file is:

    $agentcontactform = get_post_meta($post->ID, "contactformshortcode_value", true);

    Their code to display the info is:

    ?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<?php
    	$agent = "";
    	$agent2 = "";
    	include get_template_directory() . '/includes/variables.php';
    	$contactformsubject = get_the_title();
    	?>

    The sidebar code:

    $theagent = $agent;
    $theagent2 = $agent2; ?>
    <?php include get_template_directory() . '/includes/related.php'; ?>
    
    <?php if (get_option('wp_site') == "Real Estate") { ?>
    	<?php if (get_option('wp_showcontactform') == "show") { ?>
    
    		<div id="contactagent">
    
    			<?php
    				global $wpdb;
    				$sql = " SELECT *
    				FROM $wpdb->posts AS p
    				WHERE p.post_type = 'agent'
    				AND p.post_title = '". $theagent ."'";
    				$agentarray = $wpdb->get_results($sql);
    
    				$sql2 = " SELECT *
    				FROM $wpdb->posts AS p
    				WHERE p.post_type = 'agent'
    				AND p.post_title = '". $theagent2 ."'";
    				$agentarray2 = $wpdb->get_results($sql2);
    			?>
    
    			<?php if ($agentarray) { ?>
    			<?php foreach ($agentarray as $post) { ?>
    				<?php setup_postdata($post); ?>
    				<?php include get_template_directory() . '/includes/variables.php' ?>
    
    					<h3>
    						<?php echo get_option('wp_agentcontactustext');  ?>
    					</h3>
    					<div class="agentbox">
    						<h4 class="bar"><?php the_title() ?></h4>
    						<?php
    						$arr_sliderimages = get_gallery_images();
    						if ($arr_sliderimages) { ?>
    							<?php $resized = aq_resize($arr_sliderimages[0], 80, 100, true); ?>
    							<img width="80" height="100" alt="" src="<?php echo $resized ?>" />
    						<?php } ?>
    
    						<p>
    						<?php if ($agenttitle) { ?>
    							<strong><?php echo $agenttitle ?></strong><br />
    						<?php } ?>
    
    						<?php if($agentphoneoffice) { ?>
    							<?php echo get_option('wp_agentphone1') . ": " . $agentphoneoffice ?><br />
    						<?php } ?>
    
    						<?php if($agentphonemobile) { ?>
    							<?php echo get_option('wp_agentphone2') . ": " . $agentphonemobile ?><br />
    						<?php } ?>
    
    						<?php if($agentfax) { ?>
    							<?php echo get_option('wp_agentfax') . ": " . $agentfax ?><br />
    						<?php } ?>
    
    						<a href="<?php the_permalink() ?>"><?php echo get_option('wp_otherlistings') ?></a>
    						</p>
    						<div style="clear: left;"></div>
    						<?php if ($agentarray2) { ?>
    							<a class="btn btn-block" data-toggle="collapse" data-target="#agent1"><?php echo get_option('wp_contactformbutton_text') ?></a>
    							<div id="agent1" class="collapse"><?php echo do_shortcode($agentcontactform); ?></div>
    
    						<?php } else { ?>
    							<?php echo do_shortcode($agentcontactform); ?>
    						<?php } ?>
    					</div>
    			<?php } ?>
    
    			<?php } else { ?>
    
    					<h3><?php echo get_option('wp_contactustext') ?></h3>
    
    					<?php echo do_shortcode(stripslashes(get_option('wp_contactshortcode')));  ?>
    			<?php } ?>
    
    			<?php if ($agentarray2) { ?>
    			<?php foreach ($agentarray2 as $post) { ?>
    				<?php setup_postdata($post); ?>
    				<?php include get_template_directory() . '/includes/variables.php' ?>
    
    					<div class="agentbox">
    					<h4 class="bar"><?php the_title() ?></h4>
    						<?php
    						$arr_sliderimages = get_gallery_images();
    						if ($arr_sliderimages) { ?>
    							<?php $resized = aq_resize($arr_sliderimages[0], 80, 100, true); ?>
    							<img width="80" height="100" alt="" src="<?php echo $resized ?>" />
    						<?php } ?>
    
    						<p>
    						<?php if ($agenttitle) { ?>
    							<strong><?php echo $agenttitle ?></strong><br />
    						<?php } ?>
    
    						<?php if($agentphoneoffice) { ?>
    							<?php echo get_option('wp_agentphone1') . ": " . $agentphoneoffice ?><br />
    						<?php } ?>
    
    						<?php if($agentphonemobile) { ?>
    							<?php echo get_option('wp_agentphone2') . ": " . $agentphonemobile ?><br />
    						<?php } ?>
    
    						<?php if($agentfax) { ?>
    							<?php echo get_option('wp_agentfax') . ": " . $agentfax ?><br />
    						<?php } ?>
    
    						<a href="<?php the_permalink() ?>"><?php echo get_option('wp_otherlistings') ?></a>
    						</p>
    					<div style="clear: left;"></div>
    					<a class="btn btn-block" data-toggle="collapse" data-target="#agent2"><?php echo get_option('wp_contactformbutton_text') ?></a>
    					<div id="agent2" class="collapse"><?php echo do_shortcode($agentcontactform); ?></div>
    					</div>
    			<?php } ?>
    			<?php } ?>
    			</div><!-- end contact agent -->
    <?php }} ?>
    
    <?php if(get_option('wp_site') == "Car Sales") { ?>
    	<?php if (get_option('wp_showcontactform') == "show") { ?>
    		<div id="listingcontact">
    	<?php } ?>
    		<h3 class="bar" id="contact"><?php echo stripslashes(get_option('wp_contactustext')); ?></h3>
    		<?php echo do_shortcode(stripslashes(get_option('wp_contactshortcode')));  ?>
    		</div><!-- end listing contact -->
    	<?php } ?>
    
    	<script type="text/javascript">
    		$("input[name='your-subject']").val('<?php echo $contactformsubject ?>');
    	</script>
    Posted 11 years ago on Friday December 28, 2012 | Permalink
  14. Let's ignore cforms for a while and just focus on making Gravity Forms do what you want. You need the page title as the default value for field 3, the subject line. That is the bottom line?

    I get a maintenance mode message when I try to access this page to see the default functionality working there:
    http://www.realestateincentralflorida.com/contact-us/

    If you try the twenty ten theme or twenty eleven theme, does the sidebar form work properly to set the default subject line for the form to the post title?

    If it is something about your theme, we might have to go in an opposite direction to populate the subject line.

    Posted 11 years ago on Saturday December 29, 2012 | Permalink