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.

Populating a form

  1. BradPotter
    Member

    Hi Support,

    I am building a business directory using WP. I have created numerous custom fields that hold content like Phone, Fax, Website, etc.

    One of the custom fields is "Email Address". When a business listing is displayed, I would have a link that says "Email Us" and when you click on that link it would take you to a Gravity Form that would allow someone to contact that business. It would have to work in such a way that the email address stays hidden at all times but populates The Gravity form . In other words the person never knows the email address of that business and must use a form to contact them. Trying to avoid my members getting spammed.

    Is Gravity Forms capable of this and can you point me in the right direction?

    - EDIT -
    On closer review of 1.2 features "Dynamic Field Population" it looks like that will do what I need. The text above that video mentions populating hidden fields as well. Where can I read the documentation on Dynamic Field Population?

    Thanks

    Brad

    Posted 15 years ago on Wednesday October 14, 2009 | Permalink
  2. Hey Brad, I am working on the documentation for 1.2 and it isn't available just yet.

    Dynamic Field Population is done by either passing the data via a query string parameter, using an API hook, passing the data to the form via the shortcode or function call.

    In either event the stumbling block here is using the email you want to use in the notification routing. Currently we have a hook to do notification routing, but you want to do it dynamically and not based on existing form fields so i'll have to talk to Alex and see what is possible.

    If the email routing is possible you would have to most likely have to pass the post id for the listing to the page with the form on it and then use the API hook to get the email custom field value for that post id. Then pass that to the API hook for email routing.

    I have to first see if this is possible before I can come up with a suggested code snippet.

    Posted 15 years ago on Wednesday October 14, 2009 | Permalink
  3. Brad,
    Yes, you can do what you want with Gravity Forms.
    Here is what you need to do.
    1- Pass the post id in the query string to the page where the Form is embedded.

    2- Add a filter to perform the routing

    //Adds a filter to form id 17.
    add_filter("gform_notification_email_17", "route_notification", 10, 2);

    //Reads the custom field and returns the notification email
    function route_notification($email_to, $entry){
    $email_to = get_post_meta($_GET["post_id"], "CUSTOM_FIELD_KEY", true);
    return $email_to;
    }

    Let us know how it goes. Good Luck!

    Posted 15 years ago on Wednesday October 14, 2009 | Permalink
  4. I should point out that in Alex's sample code you will need to replace a few values such as the form id (17 in this example) and the custom field key that contains the email address.

    Posted 15 years ago on Wednesday October 14, 2009 | Permalink
  5. Raintrader
    Member

    Alex,

    i would like to to the same thing.
    could you please explain how the filter thing works.
    Where do i have to enter that code you posted??

    Posted 15 years ago on Wednesday October 21, 2009 | Permalink
  6. Raintrader,
    The filter will basically let you dynamically change the email that the notification will be sent to. In this case, the email is stored in a the post's custom field.

    You can add the code snippet above to the functions.php file inside your theme folder (i.e /wp-content/themes/your_theme/functions.php).

    As Carl pointed out, you will need to replace some values in the code snippet. The Form Id (17 in my example) and the custom field key ("CUSTOM_FIELD_KEY" in my example).

    Good Luck!

    Posted 15 years ago on Wednesday October 21, 2009 | Permalink
  7. Raintrader
    Member

    Thanx Alex that made things more clear.

    Just two more questions :

    #1

    if i embed the form in every Post is it possible to get a custom field from the actual diplayed Post with the method above.
    If so i dont need to pass the Post ID.
    Am i right ??

    #2
    Another Senario

    is it possible to get acces to non post values (e.g not Customfileds)a user submitted using Form A and use them to populate fileds in Form B.

    Thanks a lot

    Posted 15 years ago on Wednesday October 21, 2009 | Permalink
  8. Raintrader,

    #1 Yes you are right.

    #2 Yes, you can do that. To do that, you will basically need to string two forms together. The first form's confirmation page will be configured to go the the second page and pass some query string values. The second form will be configured to accept those query string values to populate the fields.

    Sounds like you are having some fun with Gravity Forms.
    Let me know how it turns out.

    Posted 15 years ago on Wednesday October 21, 2009 | Permalink
  9. Raintrader
    Member

    Yes i really enjoy GF,

    with this method i have to use 2 forms tied toghether as you mentioned.
    But i need them kind of independent form each other.

    Example

    User A submitts a Post with Form A
    includig Tilte,Post,custom Fields as well as Contact,Shoesize,...(non post fileds)
    On submit the Post is created

    When this Post is displayed on my Site there is FORM B attached.
    So when a visitor to my Site submits Form B i want it to send an email including values that User A provided (Contact,Shoesize) and wich are not stored with the Post.

    In other Words how can i acces the Form Entires User A made to use them in Form B without directly passing field from Form A to Form B.

    I guess i need to establish a kind of Post ID - Entry Id Realtion.

    Hope that made Intenion a bit more clear ( always hard to explain things in an other Language)

    Sascha

    Posted 15 years ago on Wednesday October 21, 2009 | Permalink
  10. Sascha,
    I understand what you are trying to do now. It will take a little bit more code, but we still can get it done.

    1- Setup Form A, and get the IDs for all fields you would like to be "sent" to Form B. You can get the Ids by looking at the html source of the form. The li containing the field will have the field id in it's ID attribute. It is formatted like such: "field_FORMID_FIELDID"

    2- Add hidden fields to Form B. One for each field you want to send to the user.
    Setup this hidden fields to "allow field to be populated dynamically" and give it a parameter name (i.e. shoesize)

    3- Add the following code to your functions.php (this will only populate one field. to populate multiple fields, you will need to add this multiple times with the proper values replaced)


    add_filter("gform_field_value_shoesize", "populate_shoesize");
    function populate_shoesize(){
    global $post;
    global $wpdb;
    $table_name = $wpdb->prefix . "rg_lead";

    //getting the entry id that generated this post
    $entry_id = $wpdb->get_var($wpdb->prepare("select id from $table_name where post_id=%d", $post->ID));

    $shoesize = "";
    if(!empty($entry_id)){

    //loading the entry with all fields
    $entry = RGFormsModel::get_lead($entry_id);

    //getting one of the entry's fields (by ID - The ID can be found by looking at the form's html source. The input will be formated as "input_ID").
    $shoesize = $entry[1]; //The 1 here is the id of the field to be returned. You can get it by looking at the html source of the form.
    }

    return $shoesize;
    }

    In the following line, "shoesize" should be replaced with the parameter name you gave your hidden field on Form B.


    add_filter("gform_field_value_shoesize", "populate_shoesize");

    AND in the following line, replace 1 with your field id from Form A

    $shoesize = $entry[1];

    Now you can setup your notification using this hidden fields and the values will be sent to the user.

    NOTE: This is method performs a couple of queries for each field you have to populate, so it may not be a great idea to use this method if you are loading a bunch of fields. You probably won't notice any performance issues if you have less than 10 fields, I don't think.

    Posted 15 years ago on Wednesday October 21, 2009 | Permalink
  11. Raintrader
    Member

    I have a form embeded @ the bottom of post.

    Now i would like to read out the custom post field called "infomail" wich i would like to use as the User/Admin Notification "send to"-adress.

    I added the following to my functions.php

    <?php add_filter("gform_notification_email_2","route_notification",10,2);
    function route_notification($email_to,$entry){
    $email_to = get_post_meta($_GET["post_id"],"infomail",true);
    return $email_to;
    }
    ?>
    

    since that my Admin notification is no longer sent.

    Any clues ?

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  12. Since your form is embeded in the post, use the following instead:


    <?php add_filter("gform_notification_email_2","route_notification",10,2);
    function route_notification($email_to,$entry){
    global $post;
    $email_to = get_post_meta($post->ID,"infomail",true);
    return $email_to;
    }
    ?>

    Posted 15 years ago on Tuesday October 27, 2009 | Permalink
  13. Raintrader
    Member

    Yeeha that worked perfect.
    i already tried it before with $post->ID as iam using the form embeded in the posts.
    But i didnt tried the "global $post;" thingy.

    Thanx for helping me out.

    GF is an absolute cool tool for my needs.
    Cant wait the next release and the feautures that about to come.

    Without beeing too demanding i would love to see the following in GF somewhre in Times.

    # the possibility to populate an external database (mysql /sqlite ) directly from Gforms.
    I know its already possible now thru passing fields via Url.
    What im looking for is to have an external Client Database that holds their Contact Data as well as the Post Url or Post Id they submitted.
    The Custumer created Post it self will remain in Wordpress Database.
    That way you dont loose all of your Data in case something happens to your Wp installation. Further you could acces the External DB via File Maker (or other DB-Clients) without messing up the WP Database.

    # An Autoincrement Number Field for creating stuff like Custumer ID or Product IDs

    That said thanx again for the excelent support.

    Sascha

    Posted 15 years ago on Tuesday October 27, 2009 | Permalink
  14. Nice! I am glad you got it to work.
    Thanks for the support.

    Posted 15 years ago on Tuesday October 27, 2009 | Permalink