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.

gform_pre_render - are post variables available?

  1. dochara
    Member

    I've searched for this, and made several attempts to resolve it without sucess.

    Essentially, I am using a single form and populating fields dynamically with post meta from the post where the form is embedded. That's working fine.

    However there is one field I want to appear ONLY when a certain post meta value is set.

    I tried to use gform_pre_render to achieve this, but I am realising that post parameters (I used $global posts; in my function) are unavailable. Is this the case? If so, is there any later point at which a field could be unset if it's not needed?

    Thank you.

    Posted 12 years ago on Monday January 16, 2012 | Permalink
  2. Assuming you are displaying your Gravity Form on a post/page, the $post global should be available. Could you share the specific code you are using and perhaps a link to the page?

    Posted 12 years ago on Monday January 16, 2012 | Permalink
  3. dochara
    Member

    I got around it another way. I just made the field required, and the unset it if it was not needed. It was my bad function and not the absence of post data that was complicating things. :)

    In case it helps anyone else, this is what I was trying to do and what worked.

    Some products on this site require that the person purchasing declares that they have insurance. It should be clear what's happening here from that.

    function sd_hide_or_require_insured($form){
    	$insuredfield = array('Insured');
    	global $post;
    	$needsinsurance = get_post_meta($post->ID,'_sd_prod_insurance',true);
    	if ($needsinsurance==0) {
    		foreach($form['fields'] as $key=>$field) {
    			if(in_array($field['label'], $insuredfield)) {
    				unset($form['fields'][$key]);
    			}
    		}
    	}
        return $form;
    }
    Posted 12 years ago on Monday January 16, 2012 | Permalink
  4. Great! Happy to hear you got this working.

    Posted 12 years ago on Monday January 16, 2012 | Permalink

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