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.

Error trying to post to external URL AND redirect in GF

  1. I added 'gform_after_submission' function to post the form data to an external URL. I used cURL to do the post.

    It works perfectly as long as I don't ALSO redirect the user within GF to another page. If all I do is show a message, the external post works fine. Once I add the redirect to another URL in GF, I get an error message: "Cannot modify header information - headers already sent", and it points to the line in the GF code: "header("Location: {$confirmation["redirect"]}");"

    I'd like to post the form data to an external URL (Act-On) AND then redirect the user to a different page.

    Ideas?

    Posted 13 years ago on Thursday February 16, 2012 | Permalink
  2. Hi, copysmith,

    I need just a bit more information. Is the redirect within Gravity Forms setup in the admin? Do you have the Confirmation as a Page or Redirect with a full URL? I did some testing on my end and didn't have that error. I setup a post like the example on this page (http://www.gravityhelp.com/documentation/page/Gform_after_submission) with my Confirmation set as a redirect.

    Can you supply the code you put into the gform_after_submission hook?

    Posted 13 years ago on Thursday February 23, 2012 | Permalink
  3. Sorry... solved the problem several days ago by placing the cURL code on the confirmation page. Yes, the confirmation page is a redirect with a full URL. Here's what I had as the hook:

    add_action('gform_after_submission_1', 'post_to_act_on_form', 10, 2);
    function post_to_act_on_form($entry, $form) {
    
    if (!function_exists('curl_init')) {
    error("Curl is not setup on this PHP server and is required for this script");
    }
    else {
    $row_arr = array();
    $row_arr["First Name"] = stripslashes($entry['11.3']);
    $row_arr["Last Name"] = stripslashes($entry['11.6']);
    $row_arr["E-mail Address"] = stripslashes($entry['12']);
    $row_arr["Quiz1"] = stripslashes($entry['13']);
    $row_arr["Quiz2"] = stripslashes($entry['14']);
    $row_arr["Quiz3"] = stripslashes($entry['15']);
    $row_arr["Quiz4"] = stripslashes($entry['16']);
    $row_arr["Quiz5"] = stripslashes($entry['17']);
    $row_arr["Quiz6"] = stripslashes($entry['18']);
    $row_arr["Quiz7"] = stripslashes($entry['19']);
    $row_arr["Quiz8"] = stripslashes($entry['20']);
    $row_arr["Quiz9"] = stripslashes($entry['21']);
    $row_arr["Quiz10"] = stripslashes($entry['22']);
    // Post to Act-On form
    $ch2 = curl_init();
    if (curl_error($ch2) != "") { echo "Error: $error\n";}
    
    // Point to Act-On External Post URL
    curl_setopt($ch2, CURLOPT_URL, "http://www.actonsoftware.com/acton/eform/1854/0003/d-ext-0001");
    
    // Set the method to POST
    curl_setopt($ch2, CURLOPT_POST, 1);
    
    // Pass POST data
    curl_setopt($ch2, CURLOPT_USERAGENT, getenv("HTTP_USER_AGENT"));
    curl_setopt($ch2, CURLOPT_POSTFIELDS, http_build_query($row_arr, '', '&'));
    curl_exec($ch2);
    curl_close($ch2); // close cURL resource
    }
    }
    add_action('gform_after_submission_1', 'post_to_act_on_form', 10, 2);
    function post_to_act_on_form($entry, $form) {
    
    if (!function_exists('curl_init')) {
    error("Curl is not setup on this PHP server and is required for this script");
    }
    else {
    $row_arr = array();
    $row_arr["First Name"] = stripslashes($entry['11.3']);
    $row_arr["Last Name"] = stripslashes($entry['11.6']);
    $row_arr["E-mail Address"] = stripslashes($entry['12']);
    $row_arr["Quiz1"] = stripslashes($entry['13']);
    $row_arr["Quiz2"] = stripslashes($entry['14']);
    $row_arr["Quiz3"] = stripslashes($entry['15']);
    $row_arr["Quiz4"] = stripslashes($entry['16']);
    $row_arr["Quiz5"] = stripslashes($entry['17']);
    $row_arr["Quiz6"] = stripslashes($entry['18']);
    $row_arr["Quiz7"] = stripslashes($entry['19']);
    $row_arr["Quiz8"] = stripslashes($entry['20']);
    $row_arr["Quiz9"] = stripslashes($entry['21']);
    $row_arr["Quiz10"] = stripslashes($entry['22']);
    // Post to Act-On form
    $ch2 = curl_init();
    if (curl_error($ch2) != "") { echo "Error: $error\n";}
    
    // Point to Act-On External Post URL
    curl_setopt($ch2, CURLOPT_URL, "http://www.actonsoftware.com/acton/eform/1854/0003/d-ext-0001");
    
    // Set the method to POST
    curl_setopt($ch2, CURLOPT_POST, 1);
    
    // Pass POST data
    curl_setopt($ch2, CURLOPT_USERAGENT, getenv("HTTP_USER_AGENT"));
    curl_setopt($ch2, CURLOPT_POSTFIELDS, http_build_query($row_arr, '', '&'));
    curl_exec($ch2);
    curl_close($ch2); // close cURL resource
    }
    Posted 13 years ago on Thursday February 23, 2012 | Permalink
  4. Nice. Glad you got everything working!

    Posted 13 years ago on Thursday February 23, 2012 | Permalink

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