0

I am trying to implement a redirect to a thank you page once the CURL has been submitted. However, since i am calling the config.php file within my html, there are some validation calls i am make which is bringing up the following error message:

Warning: Cannot modify header information - headers already sent by (output started at /home/main/public_html/index.php:162) in /home/main/public_html/config.php on line 89

HTML Snippet code:

    <?php include('config.php');?>

    <form class="form-contact" id="contactform" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">

PHP CODE:

    <?php

//Initialize the $query_string variable for later use
$query_string = "";

$error = "";


if(isset($_POST['submit'])){

    if ($_POST['first_name'] == "") {
        $error .= "Please enter in your first name.<br>";
    } elseif (!preg_match("/^[a-zA-Z ]*$/",$_POST['first_name'])) {
                $error .= "Please enter in a valid first 

name.<br>";
        }

    if($_POST['last_name'] == ""){
        $error .= "Please enter in your last name.<br>";
      } elseif (!preg_match("/^[a-zA-Z ]*$/",$_POST['last_name'])){
                $error .= "Please enter in a valid last name.<br>";
        }

    if($_POST['email'] == ""){
        $error .= "Please enter in your email address.<br>";
    } elseif (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$_POST['email'])){
            $error .= "Please enter in a valid email address.<br>";
        }

    if($_POST['company'] == ""){
        $error .= "Please enter in your company name.<br>";
        } elseif (!preg_match("/^[a-zA-Z ]*$/", $_POST['first_name'])) {
                $error .= "Please enter in a valid company 

name.<br>";
            }


    if(isset($error) && trim($error) != ""){
        //echo $error;
    }else{
            if ($_POST) {

            //Initialize the $kv array for later use
            $kv = array();

            //For each POST variable as $name_of_input_field => 

$value_of_input_field
            foreach ($_POST as $key => $value) {

            //Set array element for each POST variable (ie. 

first_name=Arsham)
            $kv[] = stripslashes($key)."=".stripslashes($value);


            }


            //Create a query string with join function separted by &
            $query_string = join("&", $kv);
            }
            //Check to see if cURL is installed .
            if (!function_exists('curl_init')){
            die('Sorry cURL is not installed!');
            }

            //The original form action URL from Step 2 :)
            $url = 

'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

            //Open cURL connection
            $ch = curl_init();


            //Set the url, number of POST vars, POST data
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, count($kv));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);

            //Set some settings that make it all work :)
            curl_setopt($ch, CURLOPT_HEADER, FALSE);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

            //Execute SalesForce web to lead PHP cURL
            $result = curl_exec($ch);

            //close cURL connection
            curl_close($ch);

ob_start();

//script

header("Location:thanks.php");

ob_end_flush();


    }

};




?>
jagmitg
  • 4,236
  • 7
  • 25
  • 59
  • @jeroen I have gone through that in detail, yes the error message is the same but the issue still remains. If you read the last bit of the php code, you can see that obstart has been implemented, it just doesnt work. – jagmitg Mar 14 '14 at 22:03
  • Better not ouput anything until the very end, but if you must use `ob_start()`, you should put it at the very start, at least before line 162 of `index.php`. – jeroen Mar 14 '14 at 22:04

0 Answers0