views:

207

answers:

1

I have a PHP form that mail()s the form data on submit and then if successful returns them to the referring page (in other words keeping them on the same page as the form) and appends ?success=TRUE to the URL.

The question is, how would I implement the AdWords and Yahoo Search Marketing conversion code snippets to trigger only when the form is submitted? For functionality purposes, it is unfortunately not feasible to send them to another page on submit which would have been the easiest way to do it.

The relevant code from the form submit action that mails the results and sends them back to the homepage is below. I have a hunch it might be as simple as outputting the conversion tracking code snippets in the if statement at the end there but I'm not sure if that is correct or the syntax to properly do that.

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

$fname = $_POST['posFName'];
$lname = $_POST['posLName'];
$phone = $_POST['posPhone'];
$email = $_POST['posEmail'];
$note = $_POST['posText'];

$to = $yourEmail;
$subject = $yourSubject;

$message = "From: $fname $lname\n\n Phone: $phone\n\n Email: $email\n\n Note: $note";

$headers = "From: ".cleanPosUrl($_POST['posFName']. " " .$_POST['posLName'])." \r\n";

$headers .= 'To: '.$yourName.' '."\r\n";

$mailit = mail($to,$subject,$message,$headers);

if ( @$mailit ) {
     header('Location: '.$referringPage.'?success=true');
     }

else {
     header('Location: '.$referringPage.'?error=true');
     }
    }
A: 

Outputting it in the if-Statement would be a possibility, but the script you posted adds another way to do it as it redirects to the $referringPage - if the mail was successfully sent. And that's the only event you want to track a conversion.

So edit the code of $referringPage (the page that holds the form fields) and add:

<?php
if($_GET['success'] == 'true') {
    echo "...";
}
?>

"..." ofcourse has to be replaced by the Adwords conversion Code Google gave you. If you add it to your question, I could even add it to my answer.

Jan P.