wrathican Posted November 6, 2007 Share Posted November 6, 2007 Hi Thanks for taking a look at this post. I really need help with a booking form i created in php for a client. here is the sample code (i do not expect you to read it, i explain what happens at the bottom): <?php function sendbooking($name, $email, $house, $street, $town, $postcode, $home, $mobile, $tour, $price, $type, $day, $month, $year, $experience, $health) { //this is gets the name of the tour instead of id $query = "SELECT * FROM cy_list WHERE li_id='" . $tour . "'"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $tourn = $row[2]; } if (($type == 'course') && ($tourn == 'INTERMEDIATE')) { $sendto = "[email protected]"; } elseif (($type == 'course') && ($tourn == 'BEGINNERS')) { $sendto = "[email protected]"; }elseif ($type == 'tour') { $sendto = "[email protected]"; }else{ $sendto = "[email protected]"; } $subject = "Course/Tour Booking"; $headers = "From: " . $_POST['name']; $headers .= "<" . $_POST['email'] . ">\r\n"; $headers .= "Reply To: " . $_POST['email'] . "\r\n"; $headers .= "Return-Path: " . $_POST['email']; //starts collecting the form vars. $type = $_POST['type']; $name = $_POST['name']; $email = $_POST['email']; $house = $_POST['house']; $street = $_POST['street']; $town = $_POST['town']; $postcode = $_POST['postcode']; $home = $_POST['home']; $mobile = $_POST['mobile']; $price = $_POST['price']; $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $date = $day . "/" . $month . "/" . $year; $experience = $_POST['experience']; $health = $_POST['health']; //put form vars into one variable $booking = "\nName: " . $name . "\n"; $booking .= "E-Mail: " . $email . "\n"; $booking .= "House no/name: " . $house . "\n"; $booking .= "Street: " . $street . "\n"; $booking .= "Town: " . $town . "\n"; $booking .= "Postcode: " . $postcode . "\n"; $booking .= "Home No: " . $home . "\n"; $booking .= "Mobile: " . $mobile . "\n"; $booking .= "Tour: " . $tourn . "\n"; $booking .= "Prices: " . $price . "\n"; $booking .= "Date: " . $date . "\n"; $booking .= "Experience: " . $experience . "\n"; $booking .= "Health: " . $health . "\n"; //$body is whole email message sent to the user/owner $body = "There has been a new request for a booking:" . $booking; if (mail($sendto, $subject, $body, $headers)) { $sendto = $_POST['email']; $subject = "CycleYorkshire.co.uk E-Mail"; $headers = "From: Iain Johnson"; $headers .= "<[email protected]>\r\n"; $headers .= "Reply To: [email protected]\r\n"; $headers .= "Return-Path: [email protected]"; $body = "Thank you for your booking. Here is a copy of the booking you have made: " . $booking; mail($sendto, $subject, $body, $headers); echo "Thank you for your booking. You will receive a copy of your booking shortly. Please do not forget to check you 'Junk' folder as sometimes these emails can be thought of as spam."; } else { echo "I'm sorry. There seems to be a problem. Please go <a href='/booking.php'>back</a> and try again."; } } if(!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['house']) && !empty($_POST['street']) && !empty($_POST['town']) && !empty($_POST['postcode']) && !empty($_POST['home']) && !empty($_POST['mobile']) && !empty($_POST['tour']) && !empty($_POST['price']) && !empty($_POST['day']) && !empty($_POST['month']) && !empty($_POST['year']) && !empty($_POST['experience']) && !empty($_POST['health'])) { sendbooking($_POST['name'],$_POST['email'],$_POST['house'],$_POST['street'],$_POST['town'],$_POST['postcode'],$_POST['home'],$_POST['mobile'],$_POST['tour'],$_POST['price'],$_POST['type'],$_POST['day'],$_POST['month'],$_POST['year'],$_POST['experience'],$_POST['health']); }else{ ?><p>To pay for a course/tour please send a personal cheque made out to Iain Johnson or Cycle Yorkshire and send to the following address:<br />Cycle Yorkshire<br />21 Ashbourne Road<br />Bradford<br />West Yorkshire<br />BD2 4AH<br /><br />Please fill out the form below in order to make a booking.<br>*Please note that all fields are required:<br> <form name="form2" method="post"> <p>Name:<br> <?php if($_POST['name'] == "") { echo '<input name="name" type="text" id="name" /><br>'; }else{ echo '<input name="name" type="text" id="name" value="' . $_POST['name'] . '" /><br>'; } ?> E-Mail:<br> <?php if($_POST['email'] == "") { echo '<input name="email" type="text" id="email" /><br>'; }else{ echo '<input name="email" type="text" id="email" value="' . $_POST['email'] . '" /><br>'; } ?> House no/name:<br> <?php if($_POST['house'] == "") { echo '<input name="house" type="text" id="house" /><br>'; }else{ echo '<input name="house" type="text" id="house" value="' . $_POST['house'] . '" /><br>'; } ?> Street:<br> <?php if($_POST['street'] == "") { echo '<input name="street" type="text" id="street" /><br>'; }else{ echo '<input name="street" type="text" id="street" value="' . $_POST['street'] . '" /><br>'; } ?> Town/City:<br> <?php if($_POST['town'] == "") { echo '<input name="town" type="text" id="town" /><br>'; }else{ echo '<input name="town" type="text" id="town" value="' . $_POST['town'] . '" /><br>'; } ?> Postcode:<br> <?php if($_POST['postcode'] == "") { echo '<input name="postcode" type="text" id="postcode" maxlength="8"/><br>'; }else{ echo '<input name="postcode" type="text" id="postcode" value="' . $_POST['postcode'] . '" maxlength="8"/><br>'; } ?> Home Telephone no:<br> <?php if($_POST['home'] == "") { echo '<input name="home" type="text" id="home" maxlength="11"/><br>'; }else{ echo '<input name="home" type="text" id="home" value="' . $_POST['home'] . '" maxlength="11"/><br>'; } ?> Mobile:<br> <?php if($_POST['mobile'] == "") { echo '<input name="mobile" type="text" id="mobile" maxlength="11"/><br>'; }else{ echo '<input name="mobile" type="text" id="mobile" value="' . $_POST['mobile'] . '" maxlength="11"/><br>'; } ?> Course/Tour Attending:<br> <select name="tour" onchange=form2.submit()> <option> </option> <?php include '../CycleYorkshire/include/misc.inc'; include '../CycleYorkshire/include/opendb.inc'; $tourp = $_POST['tour']; $query = "SELECT * FROM cy_list"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $tourid = $row[0]; $name = $row[2]; if($tourp == $tourid) { echo '<option value="' . $tourid . '" selected>' . $name . '</option>'; }else{ echo '<option value="' . $tourid . '">' . $name . '</option>'; } } ?> </select><br> <?php $tour = $_POST['tour']; $query = "SELECT * FROM cy_list WHERE li_id='" . $tour . "'"; $result = mysql_query($query); while($pri = mysql_fetch_array($result,MYSQL_NUM)) { $price = $pri[4]; $type = $pri[3]; } echo "Price:<br>\n"; echo "<input disabled value='£" . $price . "'>\n"; echo "<input type='hidden' value='" . $price . "' name='price'><br>"; echo "<input type='hidden' value='" . $type . "' name='type'><br>"; ?>Date Required:<br> <?php $month = $_POST['month']; $year = $_POST['year']; $dayp = $_POST['day']; if ($month == "Jan" or $month == "Mar" or $month == "May" or $month == "Jul" or $month == "Aug" or $month == "Oct" or $month == "Dec" or $month == ""){$maxday = 31;} if ($month == "Feb") {$maxday = 28;} if ($month == "Feb" && $year == "2008" or $year == "2012") {$maxday = 29;} if ($month == "Apr" or $month == "Jun" or $month == "Sep" or $month == "Nov") {$maxday = 30;} ?> <select name="day"> <option> </option> <?php $day = 1; while($day<=$maxday) { if($dayp == $day) { echo "<option selected>" . $day . "</option>"; }else{ echo "<option>" . $day . "</option>"; } $day++; } ?> </select> <select name="month" onchange=form2.submit()> <?php if($month == "") { echo "<option selected> </option>"; }else{ echo "<option> </option>"; } if($month == "Jan") { echo "<option selected>Jan</option>"; }else{ echo "<option>Jan</option>"; } if($month == "Feb") { echo "<option selected>Feb</option>"; }else{ echo "<option>Feb</option>"; } if($month == "Mar") { echo "<option selected>Mar</option>"; }else{ echo "<option>Mar</option>"; } if($month == "Apr") { echo "<option selected>Apr</option>"; }else{ echo "<option>Apr</option>"; } if($month == "May") { echo "<option selected>May</option>"; }else{ echo "<option>May</option>"; } if($month == "Jun") { echo "<option selected>Jun</option>"; }else{ echo "<option>Jun</option>"; } if($month == "Jul") { echo "<option selected>Jul</option>"; }else{ echo "<option>Jul</option>"; } if($month == "Aug") { echo "<option selected>Aug</option>"; }else{ echo "<option>Aug</option>"; } if($month == "Sep") { echo "<option selected>Sep</option>"; }else{ echo "<option>Sep</option>"; } if($month == "Oct") { echo "<option selected>Oct</option>"; }else{ echo "<option>Oct</option>"; } if($month == "Nov") { echo "<option selected>Nov</option>"; }else{ echo "<option>Nov</option>"; } if($month == "Dec") { echo "<option selected>Dec</option>"; }else{ echo "<option>Dec</option>"; } ?> </select> <select name="year" onChange=form2.submit()> <?php if($year == "") { echo "<option selected> </option>"; }else{ echo "<option> </option>"; } if($year == 2007) { echo "<option selected>2007</option>"; }else{ echo "<option>2007</option>"; } if($year == 2008) { echo "<option selected>2008</option>"; }else{ echo "<option>2008</option>"; } if($year == 2009) { echo "<option selected>2009</option>"; }else{ echo "<option>2009</option>"; } ?> </select><br> Previous MTB experience:<br> <?php if($_POST['experience'] == "") { echo '<textarea name="experience" cols="30" rows="5" id="experience"></textarea><br>'; }else{ echo '<textarea name="experience" cols="30" rows="5" id="experience">' . $_POST['experience'] . '</textarea><br>'; } ?> General health and fitness: <br> <?php if($_POST['health'] == "") { echo '<textarea name="health" cols="30" rows="5" id="health"></textarea><br>'; }else{ echo '<textarea name="health" cols="30" rows="5" id="health">' . $_POST['health'] . '</textarea><br>'; } ?> <input type="submit" name="Submit" value="Submit" /> </p> </form> <?php } ?> If you havent read/understood this then here is the explanation: the user fills out the form and selects dates and courses. the course titles and prices are stored in a mysql DB so when the user selects a course the page refreshes and shows the price. the date also makes the page refresh when the month/year is changed so that the tight amount of days is shown in the drop down menu. both of these use the onchange=submit handler. all of a sudden this has stopped working on my clients server. I want to change the form so it isnt as long and also add an image verification section to the bottom. If possible i would also like to stop the page refreshing when the user changes an option as they could fill out the form and decide the want a different date and once they change the month the form submits. i know this is probably a really bad way of getting it done and i have no excuse why i did it like this. any suggestions/modifications/help/wakeup calls/slaps are welcome as long as they help Thanks very much for your time. Link to comment https://forums.phpfreaks.com/topic/76214-urgent-need-help-with-booking-form-for-client/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.