Oh i forgot here is the PHP
<?php
if ($_SERVER['SERVER_NAME'] == "www.karstclimber.com") {
}
// -- Set values unique to this page --
define ("BOOKING_EARLIEST_TIME", 8);
define ("BOOKING_LATEST_TIME", 16);
define ("BOOKING_DAYS_NOTICE", 7);
define ("QUICKDRAW_HIRE_MAX", 12);
define ("HARNESS_HIRE_MAX", 5);
define ("HELMET_HIRE_MAX", 5);
define ("SHOE_SIZE_MIN", 36);
define ("SHOE_SIZE_MAX", 46);
define ("SHOE_SIZE_INCREMENT", 2);
define ("SHOE_HIRE_MAX", 5);
define ("MAIL_RECIPIENT", "brett@pixelonpixel.net");
// --- NO NEED TO EDIT BELOW THIS LINE ---
// #################################################################
// #################################################################
// DO NOT EDIT THIS PAGE UNLESS YOU UNDERSTAND HOW THE SCRIPTS WORK!
// Echo, that means YOU!!!
// #################################################################
// #################################################################
// -- Get POST data, if any were sent --
import_request_variables("gP", "form_");
/*
nameTitle
nameGiven
nameFamily
email
addrLine1
addrLine2
addrTown
addrState
addrPostcode
addrCountry
addrTelephone
addrFax
tripType
tripCountAdults
tripCountChildren
tripTimeHour
tripTimeMinutes
tripDateYear
tripDateMonth
tripDateDay
hireCountQuickdraws
hireCountHarnesses
hireCountHelmets
hireCountShoesSizeX
*/
// -- Set constants for this page --
define("TITLE", "KarstClimber.com :: Booking Form");
define("ROOTPATH", "../");
echo "<html>\n";
// -- Create HTML <head> element --
echo " <head>\n";
echo " <script language=\"JavaScript\" type=\"text/javascript\" src=\"booking.js\"></script>\n";
echo " </head>\n";
echo " <body onLoad=\"dateChange();\">\n";
echo " <div class=\"main\">\n";
if ($_REQUEST["mode"] == "review") {
// show review of data entered for confirmation
doreview();
} else if ($_REQUEST["mode"] == "submit") {
// submit the data and confirm
dosubmit();
} else {
// display booking form
doform();
}
echo " </div>\n";
echo " </body>\n";
echo "</html>\n";
function doform(){
$titles = array("mr" => "Mr.", "mrs" => "Mrs.", "ms" => "Ms.", "miss" => "Miss");
$shoeSizeRangeSize = ((SHOE_SIZE_MAX - SHOE_SIZE_MIN)/SHOE_SIZE_INCREMENT) + 1;
echo "<h3>Enquiry form</h3>\n";
echo "<p>To enquire about booking a guided trip or to rent equipment, please fill in this form.</p>\n";
echo " <h4>Contact Details</h4>\n";
echo " <form name=\"booking\" method=\"post\" action=\"./\" onSubmit=\"return validateForm();\">\n";
echo " <table>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitleMandatory\" style=\"width: 120px;\">Title</td>\n";
echo " <td class=\"formFieldTitleMandatory\">Given Name</td>\n";
echo " <td class=\"formFieldTitleMandatory\">Family Name</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>\n";
echo " <select id=\"nameTitle\" name=\"nameTitle\">\n";
echo " <option value=\"null\"></option>\n";
reset($titles);
while (list($value, $display) = each($titles)) {
echo " <option value=\"".$value."\"".(($_REQUEST["nameTitle"] == $value) ? " selected=\"selected\"" : "" ).">".$display."</option>\n";
}
echo " </select>\n";
echo " </td>\n";
echo " <td><input id=\"nameGiven\" name=\"nameGiven\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["nameGiven"]: "" )."\" style=\"width: 200px;\" /></td>\n";
echo " <td><input id=\"nameFamily\" name=\"nameFamily\" type=\text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["nameFamily"]: "" )."\" style=\"width: 200px;\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitleMandatory\">Email address</td>\n";
echo " <td colspan=\"2\"><input id=\"email\" name=\"email\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["email"]: "" )."\" style=\"width: 410px;\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td colspan=\"3\"> </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Address</td>\n";
echo " <td colspan=\"2\"><input name=\"addrLine1\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrLine1"]: "" )."\" style=\"width: 410px;\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td></td>\n";
echo " <td colspan=\"2\"><input name=\"addrLine2\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrLine2"]: "" )."\" style=\"width: 410px;\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Town/City</td>\n";
echo " <td colspan=\"2\"><input name=\"addrTown\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrTown"]: "" )."\" style=\"width: 200px;\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">State/Province</td>\n";
echo " <td colspan=\"2\"><input name=\"addrState\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrState"]: "" )."\" style=\"width: 200px;\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Post/Zip Code</td>\n";
echo " <td colspan=\"2\"><input name=\"addrPostcode\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrPostcode"]: "" )."\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Country</td>\n";
echo " <td colspan=\"2\"><input name=\"addrCountry\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrCountry"]: "" )."\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td colspan=\"3\"> </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Telephone</td>\n";
echo " <td colspan=\"2\"><input name=\"addrTelephone\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrTelephone"]: "" )."\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Fax</td>\n";
echo " <td colspan=\"2\"><input name=\"addrFax\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["addrFax"]: "" )."\" /></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " <h4>Booking Details</h4>\n";
echo " <table>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitleMandatory\" style=\"width: 120px;\">Trip type</td>\n";
echo " <td colspan=\"2\">\n";
echo " Private Trip<input id=\"tripPrivate\" type=\"radio\" name=\"tripType\" value=\"private\"".(($_REQUEST["tripType"] == "private") ? " checked=\"checked\"" : "" )." onclick=\"guidedTrip();\"/>\n";
echo " Group Trip<input id=\"tripGroup\" type=\"radio\" name=\"tripType\" value=\"group\"".(($_REQUEST["tripType"] == "group") ? " checked=\"checked\"" : "" )." onclick=\"guidedTrip();\" />\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td></td>\n";
echo " <td colspan=\"2\">\n";
echo " None (equipment hire only)<input id=\"tripNone\" type=\"radio\" name=\"tripType\" value=\"none\"".(($_REQUEST["tripType"] == "none") ? " checked=\"checked\"" : "" )." onclick=\"equipmentHire();\" />\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Number of adults</td>\n";
echo " <td>\n";
echo " <input id=\"tripCountAdults\" name=\"tripCountAdults\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["tripCountAdults"]: "" )."\" size=\"1\" maxlength=\"2\"".((($_REQUEST["tripType"] == "group") or ( $_REQUEST["tripType"] == "private" )) ? "" : " disabled=\"disabled\"" )." />\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Number of children</td>\n";
echo " <td>\n";
echo " <input id=\"tripCountChildren\" name=\"tripCountChildren\" type=\"text\" value=\"".(($_REQUEST["mode"] == "amend")? $_REQUEST["tripCountChildren"]: "" )."\" size=\"1\" maxlength=\"2\"".((($_REQUEST["tripType"] == "group") or ( $_REQUEST["tripType"] == "private" )) ? "" : " disabled=\"disabled\"" )."/>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitleMandatory\">Time</td>\n";
echo " <td colspan=\"2\">\n";
echo " <select name=\"tripTimeHour\">\n";
for ($i = BOOKING_EARLIEST_TIME; $i <= BOOKING_LATEST_TIME; $i++) {
echo" <option".(($_REQUEST["tripTimeHour"] == $i) ? " selected=\"selected\"" : "" ).">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
}
echo " </select> : <select name=\"tripTimeMinutes\">\n";
for ($i = 0; $i <= 45; $i += 15) {
echo " <option".(($_REQUEST["tripTimeMinutes"] == $i) ? " selected=\"selected\"" : "" ).">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
}
echo " </select>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitleMandatory\">Date</td>\n";
// Set year, month and day fields to earliest permitted value
$date = getdate();
$daysThisMonth = date("t", time());
$setDay = $date["mday"] + BOOKING_DAYS_NOTICE;
$setMonth = $date["mon"];
$setYear = $date["year"];
if ($setDay > $daysThisMonth) {
$setDay = $setDay - $daysThisMonth;
$setMonth ++;
}
if ($setMonth > 12) {
$setMonth = 1;
$setYear++;
}
$earliestYear = $setYear;
$earliestMonth = $setMonth;
$earliestDate = $setDay;
if ($_REQUEST["mode"] == "amend") {
// Set year, month and day fields to values in request variables
$setDay = $_REQUEST["tripDateDay"];
$setMonth = $_REQUEST["tripDateMonth"];
$setYear = $_REQUEST["tripDateYear"];
}
echo " <td colspan=\"2\">\n";
echo " <select id=\"tripDateDay\" name=\"tripDateDay\" onChange=\"dateChange();\">\n";
for ($i = 1; $i <= 31; $i++) {
echo" <option id=\"day".$i."\" value=\"".$i."\"".(($i==$setDay) ? " selected=\"selected\"" : NULL).">$i</option>\n";
}
echo " </select> - <select id=\"tripDateMonth\" name=\"tripDateMonth\" onChange=\"dateChange();\">\n";
for ($i = 1; $i <= 12; $i++) {
echo" <option id=\"month".$i."\" value=\"".$i."\"".(($i==$setMonth)?" selected=\"selected\"":NULL).">".date("M", mktime(0, 0, 0, $i, 01, 1997))."</option>\n";
}
echo " </select> - <select id=\"tripDateYear\" name=\"tripDateYear\" onChange=\"dateChange();\">\n";
echo " <option value=\"".$earliestYear."\"".(($earliestYear==$setYear)?" selected=\"selected\"":NULL).">".$earliestYear."</option>\n";
echo " <option value=\"".($earliestYear + 1)."\"".((($earliestYear + 1)==$setYear)?" selected=\"selected\"":NULL).">".($earliestYear + 1)."</option>\n";
echo " </select>\n";
echo " <input id=\"tripDateEarliestAllowedYear\" name=\"tripDateEarliestAllowedYear\" type=\"hidden\" value=\"".$earliestYear."\" />\n";
echo " <input id=\"tripDateEarliestAllowedMonth\" name=\"tripDateEarliestAllowedMonth\" type=\"hidden\" value=\"".$earliestMonth."\" />\n";
echo " <input id=\"tripDateEarliestAllowedDay\" name=\"tripDateEarliestAllowedDay\" type=\"hidden\" value=\"".$earliestDate."\" />\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " <h4>Equipment Hire</h4>\n";
echo " <table>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\" style=\"width: 120px;\">Quick draws</td>\n";
echo " <td colspan=\"$shoeSizeRangeSize\">\n";
echo " <select id=\"hireCountQuickdraws\" name=\"hireCountQuickdraws\"".(($_REQUEST["tripType"] == "none") ? "" : " disabled=\"disabled\"" ).">\n";
for ($i = 0; $i <= QUICKDRAW_HIRE_MAX; $i++) {
echo" <option value=\"".$i."\"".(($i == $_REQUEST["hireCountQuickdraws"]) ? " selected=\"selected\"" : "").">$i</option>\n";
}
echo " </select>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\" style=\"width: 120px;\">Harnesses</td>\n";
echo " <td colspan=\"$shoeSizeRangeSize\">\n";
echo " <select id=\"hireCountHarnesses\" name=\"hireCountHarnesses\"".(($_REQUEST["tripType"] == "none") ? "" : " disabled=\"disabled\"" ).">\n";
for ($i = 0; $i <= HARNESS_HIRE_MAX; $i++) {
echo" <option value=\"".$i."\"".(($i == $_REQUEST["hireCountHarnesses"]) ? " selected=\"selected\"" : "").">$i</option>\n";
}
echo " </select>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\" style=\"width: 120px;\">Helmets</td>\n";
echo " <td colspan=\"$shoeSizeRangeSize\">\n";
echo " <select id=\"hireCountHelmets\" name=\"hireCountHelmets\"".(($_REQUEST["tripType"] == "none") ? "" : " disabled=\"disabled\"" ).">\n";
for ($i = 0; $i <= HELMET_HIRE_MAX; $i++) {
echo" <option value=\"".$i."\"".(($i == $_REQUEST["hireCountHelmets"]) ? " selected=\"selected\"" : "").">$i</option>\n";
}
echo " </select>\n";
echo " <input type=\"hidden\" id=\"shoeSizeMin\" name=\"shoeSizeMin\" value=\"".SHOE_SIZE_MIN."\" />\n";
echo " <input type=\"hidden\" id=\"shoeSizeMax\" name=\"shoeSizeMax\" value=\"".SHOE_SIZE_MAX."\" />\n";
echo " <input type=\"hidden\" id=\"shoeSizeIncrement\" name=\"shoeSizeIncrement\" value=\"".SHOE_SIZE_INCREMENT."\" />\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\" style=\"width: 120px;\">Climbing shoes</td>\n";
for ($i = SHOE_SIZE_MIN; $i <= SHOE_SIZE_MAX; $i = $i + SHOE_SIZE_INCREMENT) {
echo " <td>\n";
echo " <select id=\"hireCountShoesSize$i\" name=\"hireCountShoesSize$i\"".(($_REQUEST["tripType"] == "none") ? "" : " disabled=\"disabled\"" ).">\n";
for ($j = 0; $j <= SHOE_HIRE_MAX; $j++) {
echo " <option value=\"".$j."\"".(($j == $_REQUEST["hireCountShoesSize$i"]) ? " selected=\"selected\"" : "").">$j</option>\n";
}
echo " </select>\n";
echo " </td>\n";
}
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\" style=\"width: 120px; text-align: right; margin-right: 20px;\">Size</td>\n";
for ($i = SHOE_SIZE_MIN; $i <= SHOE_SIZE_MAX; $i = $i + SHOE_SIZE_INCREMENT) {
echo " <td class=\"formFieldTitle\" style=\"text-align: center;\">$i</td>\n";
}
echo " </tr>\n";
echo " <tr>\n";
echo " <td colspan=\"".($shoeSizeRangeSize + 1)."\"> </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"formFieldTitle\">Special instructions</td>\n";
echo " <td colspan=\"$shoeSizeRangeSize\"><textarea name=\"specialInstructions\" style=\"width: 410px;\">".$_REQUEST["specialInstructions"]."</textarea></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td></td>\n";
echo " <td colspan=\"$shoeSizeRangeSize\"><button type=\"submit\"/>Next...</button></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " <p>If you encounter any difficulties sending your enquiry through this form, please send email to <a href=\"mailto:info@karstclimber.com\">info@karstclimber.com</a> instead.</p>\n";
echo " <input type=\"hidden\" id=\"mode\" name=\"mode\" value=\"review\" />\n";
echo " </form>\n";
}
function doreview(){
$titles = array("mr" => "Mr.", "mrs" => "Mrs.", "ms" => "Ms.", "miss" => "Miss");
echo " <h3>Enquiry form: review</h3>\n";
echo " <p>Please review the information you entered, and check that it is correct. Your email address is particularly important, as without it we may not be able to contact you.</p>\n";
echo " <h4>Contact Details</h4>\n";
echo " <table>\n";
reviewLine ("Name", $titles[$_REQUEST['nameTitle']]." ".$_REQUEST['nameGiven']." ".$_REQUEST['nameFamily']);
reviewLine ("Email Address", $_REQUEST['email']);
if ($_REQUEST['addrLine1']
||$_REQUEST['addrLine2']
||$_REQUEST['addrTown']
||$_REQUEST['addrState']
||$_REQUEST['addrPostcode']
||$_REQUEST['addrCountry']) {
echo " <tr>\n";
echo " <td colspan=\"3\"> </td>\n";
echo " </tr>\n";
}
reviewLine ("Address", $_REQUEST['addrLine1'] );
reviewLine ("", $_REQUEST['addrLine2']);
reviewLine ("Town/City", $_REQUEST['addrTown']);
reviewLine ("State/Province", $_REQUEST['addrState']);
reviewLine ("Post/Zip Code", $_REQUEST['addrPostcode']);
reviewLine ("Country", $_REQUEST['addrCountry']);
if ($_REQUEST['addrTelephone']||$_REQUEST['addrFax']) {
echo " <tr>\n";
echo " <td colspan=\"3\"> </td>\n";
echo " </tr>\n";
}
reviewLine ("Telephone", $_REQUEST['addrTelephone']);
reviewLine ("Fax", $_REQUEST['addrFax']);
echo " </table>\n";
echo " <h4>Booking Details</h4>\n";
echo " <table>\n";
$tripTypes = array ("group" => "Group trip", "private" => "Private trip", "none" => "Equipment hire only");
reviewLine ("Trip type", $tripTypes[$_REQUEST['tripType']]);
reviewLine ("Number of adults", $_REQUEST['tripCountAdults']);
reviewLine ("Number of children", $_REQUEST['tripCountChildren']);
reviewLine ("Time", $_REQUEST['tripTimeHour'].":".$_REQUEST['tripTimeMinutes']);
reviewLine ("Date", date("jS F Y", mktime(0, 0, 0, $_REQUEST['tripDateMonth'], $_REQUEST['tripDateDay'], $_REQUEST['tripDateYear'])));
echo " </table>\n";
if ($_REQUEST['tripType'] == 'none') {
echo " <h4>Equipment Hire</h4>\n";
echo " <table>\n";
reviewLine ("Quick draws", $_REQUEST['hireCountQuickdraws']);
reviewLine ("Harnesses", $_REQUEST['hireCountHarnesses']);
reviewLine ("Helmets", $_REQUEST['hireCountHelmets']);
for ($i = SHOE_SIZE_MIN; $i <= SHOE_SIZE_MAX; $i = $i + SHOE_SIZE_INCREMENT) {
reviewLine ("Shoes (Size ".$i.")", $_REQUEST['hireCountShoesSize'.$i]);
}
echo " </table>\n";
}
echo " <form name=\"booking\" id=\"booking\" method=\"post\" action=\"./\">\n";
echo " <table>\n";
reviewLine ("Special instructions", $_REQUEST['specialInstructions']);
echo " <tr>\n";
echo " <td style=\"width: 120px;\"></td>\n";
echo " <td colspan=\"2\"><button type=\"button\" onClick=\"goBack();\" />Amend details</button> <button type=\"submit\" onClick=\"return finalSubmit();\" />Submit enquiry</button></td>\n";
echo " </tr>\n";
echo " </table>\n";
reset($_REQUEST);
while (list($field, $value) = each($_REQUEST)) {
if ($field == "mode") {
$value = "amend";
}
echo " <input type=\"hidden\" id=\"".$field."\" name=\"".$field."\" value=\"".$value."\" />\n";
}
echo " </form>\n";
}
function reviewLine($title, $value) {
if ($value) {
echo " <tr>\n";
echo " <td class=\"formFieldTitle\" style=\"width: 120px;\">$title</td>\n";
echo " <td colspan=\"".$colspan."\">".$value."</td>\n";
echo " </tr>\n";
}
}
function dosubmit() {
$titles = array("mr" => "Mr.", "mrs" => "Mrs.", "ms" => "Ms.", "miss" => "Miss");
$tripTypes = array ("group" => "Group trip", "private" => "Private trip", "none" => "Equipment hire only");
$message = " --- www.karstclimber.com Booking Enquiry ---\n";
$message .= "\n";
$message .= "On ".date("l, jS F Y")." at ". date("H:i:s")." the following enquiry was received:\n";
$message .= "\n";
$message .= "Contact Details\n";
$message .= "\n";
$message .= messageLine("From", ($titles[$_REQUEST['nameTitle']]." ".$_REQUEST['nameGiven']." ".$_REQUEST['nameFamily']));
$message .= messageLine("Email", $_REQUEST['email']);
if ($_REQUEST['addrLine1']
||$_REQUEST['addrLine2']
||$_REQUEST['addrTown']
||$_REQUEST['addrState']
||$_REQUEST['addrPostcode']
||$_REQUEST['addrCountry']) {
$message .= "\n";
}
$message .= messageLine("Address", $_REQUEST['addrLine1']);
$message .= messageLine("", $_REQUEST['addrLine2']);
$message .= messageLine("", $_REQUEST['addrTown']);
$message .= messageLine("", $_REQUEST['addrState']);
$message .= messageLine("Postcode", $_REQUEST['addrPostcode']);
$message .= messageLine("Country", $_REQUEST['addrCountry']);
if ($_REQUEST['addrTelephone']||$_REQUEST['addrFax']) {
$message .= "\n";
}
$message .= messageLine("Telephone", $_REQUEST['addrTelephone']);
$message .= messageLine("Fax", $_REQUEST['addrFax']);
$message .= "\n";
$message .= "Booking Details:\n";
$message .= "\n";
$message .= messageLine ("Booking type", $tripTypes[$_REQUEST['tripType']]);
$message .= messageLine ("Booking date", date("jS F Y", mktime(0, 0, 0, $_REQUEST['tripDateMonth'], $_REQUEST['tripDateDay'], $_REQUEST['tripDateYear'])));
$message .= messageLine ("Booking time", ($_REQUEST['tripTimeHour'].":".$_REQUEST['tripTimeMinutes']));
$message .= messageLine ("Adults", $_REQUEST['tripCountAdults']);
$message .= messageLine ("Children", $_REQUEST['tripCountChildren']);
if ($_REQUEST['tripType'] == 'none') {
$message .= "\n";
$message .= "Equipment Hire:\n";
$message .= "\n";
$message .= messageLine ("Quick draws", $_REQUEST['hireCountQuickdraws']);
$message .= messageLine ("Harnesses", $_REQUEST['hireCountHarnesses']);
$message .= messageLine ("Helmets", $_REQUEST['hireCountHelmets']);
for ($i = SHOE_SIZE_MIN; $i <= SHOE_SIZE_MAX; $i = $i + SHOE_SIZE_INCREMENT) {
$message .= messageLine ("Shoes (Size ".$i.")", $_REQUEST['hireCountShoesSize'.$i]);
}
}
if ($_REQUEST['specialInstructions']) {
$message .= "\n";
$message .= "Special instructions:\n";
$message .= "\n";
$message .= str_pad("", 15).$_REQUEST['specialInstructions'];
}
$mailSubject = ("KARSTCLIMBER enquiry from ".$_REQUEST['nameGiven']." ".$_REQUEST['nameFamily']);
if (@mail(MAIL_RECIPIENT, $mailSubject, $message, "Reply-To: {$_REQUEST['email']}\r\n.X-Mailer: PHP/" . phpversion())) {
echo "<h3>Thank-you!</h3>\n";
echo "<p>Your enquiry has been sent. We will contact you as soon as possible</p>\n";
echo "<div style=\"height: 250px;\"> </div>\n";
} else {
echo "<h3>Sorry!</h3>\n";
echo "<p>Something has gone wrong, and your enquiry has not been sent. Please send mail to us at <a href=\"mailto:".MAIL_RECIPIENT."\">".MAIL_RECIPIENT."</a> instead; to save you from typing it again, here is the information from your enquiry to copy and paste into an email:</p>\n";
echo "<pre>\n";
echo $message;
echo "</pre>\n";
}
}
function messageLine ($field, $value) {
if ($value) {
return str_pad($field, 15).": ".$value."\n";
}
}
?>
and here is the JS
/* ---booking.js--- */
var eOpenMenu = null;
function validateForm() {
var status = true; // The status to return from this function. Gets set to false if there are any errors on the form.
var message = ''; // The message to display if there are errors on the form. Populated as each condition is checked.
var nameTitle = new getObj('nameTitle');
var nameGiven = new getObj('nameGiven');
var nameFamily = new getObj('nameFamily');
var email = new getObj('email');
var tripPrivate = new getObj('tripPrivate');
var tripGroup = new getObj('tripGroup');
var tripNone = new getObj('tripNone');
var tripType = !(tripPrivate.element.checked || tripGroup.element.checked || tripNone.element.checked);
// Make sure nameTitle field is not null
if (nameTitle.element.value == 'null') {
message+=('- Title\n');
status = false;
}
// Allowing nameGiven to be empty if nameFamily is Wookey is a private joke
if ((nameGiven.element.value == '') && (nameFamily.element.value.toLowerCase() != 'wookey')) {
message+=('- Given name\n');
status = false;
}
// Make sure nameFamily is not empty
if (nameFamily.element.value == '') {
message+=('- Family name\n');
status = false;
}
// Make sure email is not empty
if (email.element.value == '') {
message+=('- Email address\n');
status = false;
}
// Make sure a tripType has been selected
if (tripType) {
message+=('- Trip type\n');
status = false;
}
// Adds a polite header to the error message, if one exists.
if (message != '') {
message = ('Please fill in the following fields:\n' + message);
}
if (tripPrivate.element.checked || tripGroup.element.checked) {
var tripError = '';
var tripCountTotal = 0;
var tripCountAdults = new getObj('tripCountAdults');
tripCountTotal += Number(tripCountAdults.element.value);
var tripCountChildren = new getObj('tripCountChildren');
tripCountTotal += Number(tripCountChildren.element.value);
if ((isNaN(tripCountAdults.element.value)) || (tripCountAdults.element.value == '')) {
tripError += '- Number of adults\n';
}
if ((isNaN(tripCountChildren.element.value)) || (tripCountChildren.element.value == '')) {
tripError += '- Number of children\n';
}
if (tripError != '') {
message += ((message == '') ? '' : '\n') + 'You selected a ' + (tripPrivate.element.checked ? 'private trip' : 'group trip') + ' but did not select:\n' + tripError;
status = false;
} else if (tripCountTotal == 0) {
message += ((message == '') ? '' : '\n') + 'You selected a ' + (tripPrivate.element.checked ? 'private trip' : 'group trip') + ' but have set\n - Number of adults\n - Number of children\nto zero';
status = false;
}
}
if (tripNone.element.checked) {
var equipmentError ='';
var equipmentCount = 0;
var shoeSizeMin = new getObj('shoeSizeMin');
var shoeSizeMax = new getObj('shoeSizeMax');
var shoeSizeIncrement = new getObj('shoeSizeIncrement');
for (i = Number(shoeSizeMin.element.value); i <= Number(shoeSizeMax.element.value); i = i + Number(shoeSizeIncrement.element.value)) {
var x = new getObj('hireCountShoesSize' + i);
equipmentCount += Number(x.element.value);
}
var hireCountQuickdraws = new getObj('hireCountQuickdraws');
equipmentCount += Number(hireCountQuickdraws.element.value);
var hireCountHarnesses = new getObj('hireCountHarnesses');
equipmentCount += Number(hireCountHarnesses.element.value);
var hireCountHelmets = new getObj('hireCountHelmets');
equipmentCount += Number(hireCountHelmets.element.value);
if (equipmentCount == 0) {
message += ((message == '') ? '' : '\n') + 'You selected equipment hire, but have not chosen any equipment\n';
status = false;
}
}
if (message) {
alert (message);
}
return status;
}
function guidedTrip() {
// Changes disabled property of fields when a guided trip is selected
var x = new getObj('tripCountAdults');
x.element.disabled = false;
var x = new getObj('tripCountChildren');
x.element.disabled = false;
var x = new getObj('hireCountQuickdraws');
x.element.disabled = true;
x.element.value = '0';
var x = new getObj('hireCountHarnesses');
x.element.disabled = true;
x.element.value = '0';
var x = new getObj('hireCountHelmets');
x.element.disabled = true;
x.element.value = '0';
var shoeSizeMin = new getObj('shoeSizeMin');
var shoeSizeMax = new getObj('shoeSizeMax');
var shoeSizeIncrement = new getObj('shoeSizeIncrement');
for (i = Number(shoeSizeMin.element.value); i <= Number(shoeSizeMax.element.value); i = i + Number(shoeSizeIncrement.element.value)) {
var x = new getObj('hireCountShoesSize' + i);
x.element.disabled = true;
x.element.value = 0;
}
}
function equipmentHire() {
// Changes disabled property of fields when equipment hire is selected
var x = new getObj('tripCountAdults');
x.element.disabled = true;
x.element.value = '';
var x = new getObj('tripCountChildren');
x.element.disabled = true;
x.element.value = '';
var x = new getObj('hireCountQuickdraws');
x.element.disabled = false;
var x = new getObj('hireCountHarnesses');
x.element.disabled = false;
var x = new getObj('hireCountHelmets');
x.element.disabled = false;
var shoeSizeMin = new getObj('shoeSizeMin');
var shoeSizeMax = new getObj('shoeSizeMax');
var shoeSizeIncrement = new getObj('shoeSizeIncrement');
for (i = Number(shoeSizeMin.element.value); i <= Number(shoeSizeMax.element.value); i = i + Number(shoeSizeIncrement.element.value)) {
var x = new getObj('hireCountShoesSize' + i);
x.element.disabled = false;
}
}
function dateChange() {
// when the month or year is changed, make sure that invalid dates are disabled
var tripDateDay = new getObj('tripDateDay');
var tripDateMonth = new getObj('tripDateMonth');
var tripDateYear = new getObj('tripDateYear');
var monthDays = getMonthDays(tripDateMonth.element.value, tripDateYear.element.value);
// if currently selected date is greater than number of days in newly selected month
// set date to the last day of the month
if (Number(tripDateDay.element.value) > Number(monthDays)) {
tripDateDay.element.value = monthDays;
}
// disable dates beyond the last day of the newly selected month
for (i = 29; i <= 31; i++) {
var day = new getObj ('day'+i);
if (i <= monthDays) {
day.element.disabled = false;
} else {
day.element.disabled = true;
}
}
// get earliest date permitted from hidden fields on the form
var earliestYear = new getObj('tripDateEarliestAllowedYear');
var earliestMonth = new getObj('tripDateEarliestAllowedMonth');
var earliestDay = new getObj('tripDateEarliestAllowedDay');
if (tripDateYear.element.value == earliestYear.element.value) {
// date chosen is in the current year, set flag to disable months before the earliest permitted
var monthDisable = true;
var monthColor = 'gray';
if (Number(tripDateMonth.element.value) < Number(earliestMonth.element.value)) {
// currently selected month is before earliest permitted, reset to earliest permitted
tripDateMonth.element.value = earliestMonth.element.value;
}
if (tripDateMonth.element.value == earliestMonth.element.value) {
// date chosen is in the earliest permitted month,
// set flag to disable days before the earliest permitted
var dayDisable = true;
var dayColor = 'gray';
if (Number(tripDateDay.element.value) < Number(earliestDay.element.value)) {
// currently selected day is before earliest permitted, reset to earliest permitted
tripDateDay.element.value = earliestDay.element.value;
}
} else {
var dayDisable = false;
var dayColor = 'black';
}
} else {
var monthDisable = false;
var monthColor = 'black';
var dayDisable = false;
var dayColor = 'black';
}
// disable months prior to the earliest permitted in the current year
for (i = 1; i < Number(earliestMonth.element.value); i ++) {
var month = new getObj ('month'+i);
month.element.disabled = monthDisable;
month.style.color = monthColor;
}
// disable days prior to the earliest permitted in the current month
for (i = 1; i < Number(earliestDay.element.value); i ++) {
var day = new getObj ('day'+i);
day.element.disabled = dayDisable;
day.style.color = dayColor;
}
}
function getMonthDays(month, year) {
// return the number of days in the month
var monthsDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
monthDays = monthsDays[(month - 1)];
if ((month == 2) && isLeapYear(year)) {
monthDays = 29;
}
return monthDays;
}
function isLeapYear(year) {
// check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
if ( (Math.floor(year/4) == (year/4)) && ((Math.floor(year/100) != (year/100)) || (Math.floor(year/400) == (year/400))) )
return true;
else
return false;
}
function goBack() {
var x = new getObj ('mode');
x.element.value = 'amend';
var x = new getObj ('booking');
x.element.submit();
}
function finalSubmit() {
var x = new getObj ('mode');
x.element.value = 'submit';
return true;
}
function getObj(name) {
if (document.getElementById) {
this.style = document.getElementById(name).style;
this.element = document.getElementById(name);
}
else if (document.all) {
this.style = document.all[name].style;
this.element = document.all[name];
}
else if (document.layers) {
this.style = document.layers[name];
this.element = document.layers[name];
}
}