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 External Script/URL

  1. I'd like to use Gravity Forms to post data to an external PHP script, located here: http://www.foothillunitycenter.org/forms/emaillistform/emailform.php, rather than use the existing form, because I do want to include some form validation here.

    I found this discussion on the topic: http://www.gravityhelp.com/forums/topic/cant-find-any-instructions-to-post-form-data-to-external-url - which I think would pretty much resolve my issue, but I haven't been able to get it to work yet.

    For what I want to accomplish, do I need to add any code to functions.php? IF so, would this code work:

    add_action("gform_post_submission", "post_to_newsletter", 10, 2);
    
    function post_to_newsletter($entry, $form){
        if($form["id"] != 3) //NOTE: replace 3 with your form id
            return;
        ?>
            <form method="post" action="http://www.foothillunitycenter.org/forms/emaillistform/emailform.php" name="post_to_newsletter" id="post_to_newsletter">
                <input type="text" id="name" name="Name" value="<?php echo $entry["name"] ?>" />
                <input type="text" id="email" name="Email" value="<?php echo $entry["email"] ?>" />
    
                NOTE: $entry["1"] will return field with ID=1. You can view the field ID by inspecting that input's markup
                .... add your other fields here
    
            </form>
            <script type="text/javascript">
                document.getElementById("post_to_newsletter").submit();
            </script>
        <?php
    }

    I did try it, and it didn't seem to do anything.

    The other thing I tried was to setup a redirect in form settings. Under the confirmation tab, I entered the URL to the php form and then added teh following merge tags: name={Name:1}&email{Email:2} and that didn't seem to do the trick either.

    If anyone could guide me to the right path, that would be rad.

    Posted 7 years ago on Wednesday April 25, 2012 | Permalink
  2. David Peralty
    Administrator

    As it is currently, no that wouldn't work. You'll have to customize it a bit more to make it work. First, the form ID, then removing the note, and putting in the field ID numbers into the echo statements you have prepared.

    Can you tell me more about what you are trying to accomplish and why? I might be able to help you with an easier/better solution if I had a better understanding of what your goal is.

    Posted 7 years ago on Wednesday April 25, 2012 | Permalink
  3. Hey David,
    Thanks for the reply.

    There's a site I'm moving over to WordPress. They have a newsletter subscription form they use, currently. They get a lot of bogus signups. So I thought I could use Gravity Forms to submit the data to the form script using Post Method, while providing a verification process (recaptcha).

    Does that make sense?

    Posted 7 years ago on Wednesday April 25, 2012 | Permalink
  4. Bump. =)

    Posted 7 years ago on Tuesday May 1, 2012 | Permalink
  5. jcole
    Member

    I have a similar issue where I need to post to a PHP script on the server (ie. not external) which takes form values and generates a PDF.

    Is there a recommended method for doing this?

    Thanks,
    John

    Posted 7 years ago on Monday May 21, 2012 | Permalink
  6. Bump ++ Very interested to know if GF can post to a custom PHP script....

    Posted 7 years ago on Friday June 15, 2012 | Permalink