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.

Custom Field in Form

  1. Hi, sorry if this has been covered, have spent few hours looking through the forums but don't seem to be any the wiser.

    Am trying to get the form to insert a reference number from a custom field in the post into the form custom field.

    Might be easier to explain if I show what I'm trying to do, on each post page have set up custom fields for, property reference, bedrooms, bathrooms etc...

    http://www.baxterestates.net/?p=67

    All I would like to do is have the property reference number load into a field in the form so that when the form is received they can see what the property is that the form relates to. Have got it working where it sends the page id/title but the client really wants the reference number in the email so it can all match up with their records.

    The custom field name in the post is called ref

    Does anyone know how I can do this, have tried:

    add_filter("gform_field_value_ref", "populate_ref");
    function populate_ref(){
    $ref_value = "Test";
    return $ref_value;
    }

    which does send the value 'Test' in the form, but when I tried using:

    add_filter("gform_field_value_ref", "populate_ref");
    function populate_ref(){
    return ref("ref");
    }

    It seems to hide everything below the existing custom fields in the post.

    If anyone can help me with this would be very appreciated!

    Posted 13 years ago on Friday June 4, 2010 | Permalink
  2. Try the following. It should do the trick.

    add_filter("gform_field_value_ref", "populate_ref");
    function populate_ref($value){
        global $post;
    
        //replace "custom_field_name" with your action name
        return get_post_meta($post->ID, "custom_field_name", true);
    }
    Posted 13 years ago on Friday June 4, 2010 | Permalink
  3. Cheers, will try it out and let you know how I get on

    Posted 13 years ago on Saturday June 5, 2010 | Permalink
  4. Hi, put the code into the functions file but its not putting anything into the ref field, the form all works and sends but with the property ref field blank.

    I used:

    add_filter("gform_field_value_ref", "populate_ref");
    function populate_ref($value){
    global $post;

    //replace "custom_field_name" with your action name
    return get_post_meta($post->ID, "ref", true);
    }

    That correct? Any idea what I´m doing wrong?

    Posted 13 years ago on Saturday June 5, 2010 | Permalink
  5. The code looks good.
    Have you enabled your ref field to be populated dynamically in the field editor (advanced tab) and gave it the name "ref"?
    If so, I will need to take a closer look at it. Drop me a line at alex[at]rocketgenius.com with a WP admin login and I will see what is going on.

    Posted 13 years ago on Monday June 7, 2010 | Permalink
  6. Hi Alex, sent you an email, thankyou very much for the help

    Posted 13 years ago on Monday June 7, 2010 | Permalink