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.

Posting data to more than one gravity form table

  1. annaweaver
    Member

    Hi. I am new to Gravity Forms, having just purchased a license today. I have two forms in my site: a mailing list form (with 2 fields - name and email) and a contact form (which includes the above but also has several more). The contact form also has an opt in to the mailing box checkbox. What I want to happen is, if the user checks this box, their name and email gets posted to the table associated with the mailing list form. I have been serching for hours to find a way of doing this to no avail.

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  2. Thank you for purchasing a Gravity Forms license.

    There is currently no easy way to do this exactly as you describe it. Gravity Forms entries are always stored in one table, but they are tied to the form the entry was submitted from. If you want to store the name and email in a custom table, or a text file, or send it to a 3rd party mailing service for subscription to your newsletter, we can help with that, but to we can't create an actual Gravity Forms entry without submitting the form.

    You could incorporate a sort of "double opt-in" by sending the link to the mailing list form in the user notification from the contact form, when they opt in to the newsletter (you can take care of sending the link ONLY when the user checks the 'opt in' box using conditional shortcodes.) Then, in your HTML user notification, you can include the link to the page with the mailing list form, and pre-populate those two pieces of information you need (name and email) with just a "Submit" or "Confirm" button. That way, you've implemented double opt-in using two forms on your site and it's still seamless to the user.

    If you want to do it as single-opt in, you'll need another approach.

    What happens with the information you capture with the mailing list form?

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  3. annaweaver
    Member

    Thank you for your reply. Will give that a go. Nothing happens yet with the data from the mailing list form. My client is intending on creating a mailing list in the future so we're just capturing emails for now - they do not know which ESP they will use yet.

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  4. If you need help let us know. As I typed that out it seemed like it would not be too difficult to implement. We can help you if you get stuck.

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  5. annaweaver
    Member

    Please can you give me some pointers about how to use a conditional shortcode to send an email only to those people who have checked the opt in box? And then to prepopulate the name and address fields in the mailing list form? Haven't managed to get thee things to work. I need to hardcode the shortcodes in the page template.

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  6. How are you hardcoding the shortcodes in the template? I'm just curious. If you embed the form using the function call in a template file, be sure you enqueue the required scripts.

    Documentation:
    http://www.gravityhelp.com/documentation/page/Embedding_A_Form#Function_Call

    I will take a look at configuring these forms and see if it's simple enough to do. There are a few pieces to integrate but none of it seemed very complex.

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  7. I configured two forms as I described above. Start here:
    http://gravity.chrishajer.com/contact-form-step-1/

    I will post the forms and the procedure in a little bit.

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  8. Form 1 XML: http://pastebin.com/download.php?i=PSRn6TJp

    Form 2 XML: http://pastebin.com/download.php?i=XwPKmxH1

    Form 1 is embedded in this page:
    http://gravity.chrishajer.com/contact-form-step-1/

    [gravityform id="202" name="Contact Form (step 1)" title="false"]

    Form 2 is embedded in this page:
    http://gravity.chrishajer.com/newsletter-confirmation/

    [php]
    [gravityform id="203" name="Newsletter Form (step 2)" title="false"]
    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  9. I created form one (the contact form with more fields captured) first. Then I created form two (the shorter/newsletter form). In form 2, be sure to mark the first name, last name and email fields "Allow field to be populated dynamically" and then give those fields parameter names. I used fname, lname and eml. Then I created a page to embed each form into. You will need to know the URL for form two so you can use it in your email notification (it could have been in the text confirmation as well; the visitor would have the link immediately after form submission if that were the case.)

    After that I used the conditional shortcodes, based on the value of the answer to the newsletter question (I used values of yes and no to make things easier on myself) to show some text in the confirmation message and the user notification conditionally. In the user notification, I built a query string using the merge tag drop down, and that is where I use the URL for the page which holds the newsletter subscription page and also I use my parameter names of fname, lname and eml in addition to the merge tag drop down.

    Is that enough information to get you started?

    Posted 13 years ago on Wednesday October 31, 2012 | Permalink
  10. annaweaver
    Member

    I have been embedding this into my template file:
    <?php echo do_shortcode( '[gravityform id=2 title=false description=false]' ); ?>

    Thank you for all this. I think having the link in the confirmation will be better actually. I will try following all your instructions and let you know how I get on!

    Posted 13 years ago on Thursday November 1, 2012 | Permalink
  11. annaweaver
    Member

    Ok, it's so close to working! I'm just a bit stuck on how to send the form field values to the next form in a url string. Basically, I can't work out how to retrieve the field values properly to insert them into the query string. This is what I have so far in my functions.php.

    add_filter("gform_confirmation", "custom_confirmation", 10, 4);
    function custom_confirmation($confirmation, $form, $lead, $ajax){
    	// lamp contact form
        if($form["id"] == "2"){
    		$firstname = $form["firstname"];
    		$email = $form["email"];
    		$confirmation = '<p>Thank you, we will respond to your enquiry as soon as possible.</p>Please click here if your would like to subscribe to our <a rel="nofollow">mailing list</a>.</p>';
        }
    	// lamp mailing list
        else if($form["id"] == "1"){
            $confirmation = "Your details have been added to our mailing list, thank you.";
        }
        return $confirmation;
    }

    Sorry, not sure how to use the backtack character to get this to display as code!

    Posted 13 years ago on Thursday November 1, 2012 | Permalink
  12. annaweaver
    Member

    Ok, so it's not showing the query string above... in the a tag i have

    href=' . get_site_url() . '/lamp/mailing-list?firstname=' .  urlencode($firstname) . '&email=' . urlencode($email) . '

    If I hard code something in the urlencode brackets, rather than bringing in a variable, the fields in the following form get populated properly. I just don't know how to get the values from the first form into the query string! The field labels in the first from are firstname and email, and they have the same parameter names in the second form which needs populating.

    Posted 13 years ago on Thursday November 1, 2012 | Permalink
  13. Why are you using a function to return the confirmation message in this reply:
    http://www.gravityhelp.com/forums/topic/posting-data-to-more-than-one-gravity-form-table#post-86066

    You can certainly change the confirmation conditionally in your theme's functions.php, as you have done here, but it's easier to use the conditional shortcode, and then you also have access to the merge tags. If you are going to do everything in a function, you will need to refer to the form fields by name in your query string.

    In your code, lines 5 and 6 will need to refer to the $entry, not the $form, to get the name and the email address, so it will look more like this, but will be specific to your form field IDs:

    // if your name is the first field on the the form
    // 1.3 will be the first name
    $firstname = $entry["1.3"];
    // if your email is field 2, this is correct
    $email = $entry["2"];

    The field IDs depend on your actual form though. View the source of the page where the form is rendered and you will see the field IDs and can use those.

    Posted 13 years ago on Thursday November 1, 2012 | Permalink
  14. annaweaver
    Member

    Just got it to work. It took me a while to realise that I had to add $entry to the confirmation function parameters! Thank you for all your help Chris.

    Posted 13 years ago on Thursday November 1, 2012 | Permalink
  15. Great. Thank you for the update.

    Posted 13 years ago on Friday November 2, 2012 | Permalink

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