Courier Quote Form

Hi,

I was just wondering if someone had a minute to cast their eye over this form someones helped me create, it’s meant to be a form on my website where people can get a quote for courier work, It’s meant to use google to look up the start and end locations, work out the distance between and put it all in an email to me.

It’s using google to lookup the address when you type it in but the email it’s sending isn’t containing the addresses. Also it’s not working out the distance either unfortunately, has anyone got experience of a code like this?

Thanks
Ste

Here’s the script:

<?php

$apikey = "**key**";

$start_pre = $_POST['start'];
$start = str_replace(' ', '%20', $start_pre);

$end_pre = $_POST['end'];
$end = str_replace(' ', '%20', $end_pre);


$url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" . $start . "&destinations=" . $end . "&key=" . $apikey;

$json = file_get_contents($url);
$obj = json_decode($json);

?>


<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<? echo $apikey; ?>&amp;libraries=places"></script>

  <style id="compiled-css" type="text/css">
      .autocomplete {
    width:300px;
}
  </style>

  <script type="text/javascript">//<![CDATA[

var options = {
   componentRestrictions: {country: 'gb'}
};

    var VanillaRunOnDomReady = function() {
      
function initialize() {

    var acInputs = document.getElementsByClassName("autocomplete");

    for (var i = 0; i < acInputs.length; i++) {

        var autocomplete = new google.maps.places.Autocomplete(acInputs[i], options);
        autocomplete.inputId = acInputs[i].id;

        google.maps.event.addListener(autocomplete, 'place_changed', function () {
            document.getElementById("log").innerHTML = 'You used input with id ' + this.inputId;
        });
    }
}

initialize();

    }

var alreadyrunflag = 0;

if (document.addEventListener)
    document.addEventListener("DOMContentLoaded", function(){
        alreadyrunflag=1; 
        VanillaRunOnDomReady();
    }, false);
else if (document.all && !window.opera) {
    document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
    var contentloadtag = document.getElementById("contentloadtag")
    contentloadtag.onreadystatechange=function(){
        if (this.readyState=="complete"){
            alreadyrunflag=1;
            VanillaRunOnDomReady();
        }
    }
}

window.onload = function(){
  setTimeout("if (!alreadyrunflag){VanillaRunOnDomReady}", 0);
}

  //]]></script>

<form action="" method="post">

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<? echo $apikey; ?>&libraries=places"></script>
<p>Your Name: <input type="text" name="name"></p>
<p>Contact Email: <input type="text" name="email"></p>
<p>Pickup: <input name="start" class="autocomplete" id="ac1" placeholder="Enter pickup address" type="text" value="<? echo $start_pre; ?>"></p>
<p>Drop off: <input name="end" class="autocomplete" id="ac2" placeholder="Enter drop off address" type="text" value="<? echo $end_pre; ?>"></p>
<p>Comments: <textarea name="comments" cols="" rows=""></textarea></p>
<input type="hidden" name="sent" value="1">
<input type="submit"><br><br>
<?php

if ($_POST['sent'] == "1") {
	
$subject = "Skelmersdale Couriers Quote";

$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$from = $obj->origin_addresses[0];
$to = $obj->destination_addresses[0];

$message = "
<p>Name: $name</p>
<p>Email: $email</p>
<p>Pickup: $from</p>
<p>Drop Off: $to</p>
<p>Comments: $comments</p>
";

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: Skelmersdale Couriers <[email protected]>\r\n";
$headers .= "From: Skelmersdale Couriers <[email protected]/>\r\n";

mail($to, $subject, $message, $headers);
	
}
?>
</form>

Can you place your code between code tags please?

1 Like

first have a look at var_dump($obj); if the data is in there.

This shouldn’t be used. It is a leftover from the old days and will wipeout what you want to be on the DOM. Instead, you want to append the DOM.

var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');

script.type = 'text/javascript';

if (isOpera)
    script.src = "javascript:void(0)";


head.appendChild(script);
Sponsor our Newsletter | Privacy Policy | Terms of Service