mikehermary Posted October 4, 2008 Share Posted October 4, 2008 Hello, I am needing to have sticky select menus, check boxes, and radio buttons in a booking request form that I am using, but am unable to figure out how this will work. I will also need those fields to be validated in the the same way that the text inputs would be validated. I have included the PHP script below. <?php include('includes/corefuncs.php'); if (function_exists('nukeMagicQuotes')) { nukeMagicQuotes(); } // process the email if (array_key_exists('send', $_POST)) { $to = '[email protected]'; // use your own email address $subject = 'Booking request'; // list expected fields $expected = array('name', 'company', 'email', 'phone', 'fax', 'cell', 'departurecity', 'alternatedeparture', 'arrivalcity', 'alternatearrival', 'departuredate', 'flexdeparturedate1', 'flexdeparturedate2', 'departuretime', 'flexdeparturetime1', 'flexdeparturetime2', 'returndate', 'flexreturndate1', 'flexreturndate2', 'returntime', 'flexreturntime1', 'flexreturntime2', 'medical1', 'medical2', 'hotel1', 'hotel2', 'rental1', 'rental2', 'preferredhotel', 'specialrates', 'preferreddealer', 'specialnotes', 'furtherndetails'); // set required fields $required = array('name', 'phone', 'departurecity', 'arrivalcity', 'departuredate', 'departuretime', 'returndate', 'returntime', 'medical1', 'medical2', 'hotel1', 'hotel2', 'rental1', 'rental2'); // create empty array for any missing fields $missing = array(); // assume that there is nothing suspect $suspect = false; // create a pattern to locate suspect phrases $pattern = '/Content-Type:|Bcc:|Cc:/i'; // function to check for suspect phrases function isSuspect($val, $pattern, &$suspect) { // if the variable is an array, loop through each element // and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } } // check the $_POST array and any sub-arrays for suspect content isSuspect($_POST, $pattern, $suspect); if ($suspect) { $mailSent = false; unset($missing); } else { // process the $_POST variables foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } // otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } } // validate the email address if (!empty($email)) { // regex to ensure no illegal characters in email address $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; // reject the email address if it doesn't match if (!preg_match($checkEmail, $email)) { array_push($missing, 'email'); } } // go ahead only if not suspect and all required fields OK if (!$suspect && empty($missing)) { // build the message $message = "Name: $name\n\n"; $message .= "Company Name: $company\n\n"; $message .= "Email: $email\n\n"; $message .= "Phone number: $phone\n\n"; $message .= "Fax: $fax\n\n"; $message .= "Cell: $cell\n\n"; $message .= "Departure City: $departurecity\n\n"; $message .= "Alternate Departure: $alternatedeparture\n\n"; $message .= "Arrival City: $arrivalcity\n\n"; $message .= "Alternate Arrival: $alternatearrival\n\n"; $message .= "Departure Date: $departuredate\n\n"; $message .= "Flexible Departure Date: $flexdeparturedate1\n\n"; $message .= "Flexible Departure Date: $flexdeparturedate2\n\n"; $message .= "Departure Time: $departuretime\n\n"; $message .= "Flexible Departure Time: $flexdeparturetime1\n\n"; $message .= "Flexible Departure Time: $flexdeparturetime2\n\n"; $message .= "Return Date: $returndate\n\n"; $message .= "Flexible Return Date: $flexreturndate1\n\n"; $message .= "Flexible Return Date: $flexreturndate2\n\n"; $message .= "Return Time: $returntime\n\n"; $message .= "Flexible Return Time: $flexreturntime1\n\n"; $message .= "Flexible Return Time: $flexreturntime2\n\n"; $message .= "Medical Insurance: $medical1\n\n"; $message .= "Medical Insurance: $medical2\n\n"; $message .= "Hotel Required: $hotel1\n\n"; $message .= "Hotel Required: $hotel2\n\n"; $message .= "Preferred Hotel: $preferredhotel\n\n"; $message .= "Special Rates: $specialrates\n\n"; $message .= "Preferred Car Rental Agency: $preferreddealer\n\n"; $message .= "Special Notes: $specialnotes\n\n"; $message .= "Further Details: $furtherdetails\n\n"; // limit line length to 70 characters $message = wordwrap($message, 70); // create additional headers $additionalHeaders = ''; if (!empty($email)) { $additionalHeaders .= "\r\nReply-To: $email"; } // send it $mailSent = mail($to, $subject, $message, $additionalHeaders); if ($mailSent) { // $missing is no longer needed if the email is sent, so unset it unset($missing); } } } ?> <?php $page = 'booking_request'; ?> <?php if ($page == 'index') { $pgtitle = "Four Corners Vacations - South Pacific Specialist"; } elseif ($page == 'about') { $pgtitle = "About"; } elseif ($page == 'destinations_gallery') { $pgtitle = "Destinations Gallery"; } elseif ($page == 'specials') { $pgtitle = "Specials"; } elseif ($page == 'travel_tips') { $pgtitle = "Travel Tips"; } elseif ($page == 'booking_request') { $pgtitle = "Booking Request"; } elseif ($page == 'contact') { $pgtitle = "Contact"; } elseif ($page == 'disclaimer') { $pgtitle = "Disclaimer"; } elseif ($page == 'sitemap') { $pgtitle = "Sitemap"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo "$pgtitle"; ?></title> <link href="css/template_css.css" rel="stylesheet" type="text/css" charset="utf-8" /> <!--[if IE 6]><link href="css/ie6_css.css" rel="stylesheet" type="text/css" charset="utf-8" /><![endif]--> <!--[if IE 7]><link href="css/ie7_css.css" rel="stylesheet" type="text/css" charset="utf-8" /><![endif]--> <link rel="stylesheet" href="css/jd.gallery.css" type="text/css" media="screen" charset="utf-8" /> <script src="scripts/mootools.v1.11.js" type="text/javascript"></script> <script src="scripts/jd.gallery.js" type="text/javascript"></script> <script src="scripts/datetimepicker.js" type="text/javascript"></script> </head> <body> <div id="outerWrapper"> <div id="container"> <div id="header"> <h1><a href="index.php" title="Four Corners Vacations"></a></h1> <div id="menu"> <?php include("includes/menu.php"); ?> </div> </div> <div id="wrapper"> <div id="contentContainerOne"> <?php include ("includes/slideshow.php"); ?> </div> <div id="contentContainerTwo"> <div id="cCTWrapper"> <div id="mainCol"> <h2><a name="top">Booking Request</a></h2> <?php if ($_POST && isset($missing)) { ?> <p><em>Please complete the missing item(s) indicated.</em></p> <?php } elseif ($_POST && !$mailSent) { ?> <p><em>Sorry, there was a problem sending your message. Please try again later.</em></p> <?php } elseif ($_POST && $mailSent) { ?> <p><strong>Your message has been sent. Thank you for contacting Four Corners Vacations.</strong></p> <?php } ?> <div id="bookingRequest"> <span class="required">* required fields</span> <br /> <form id="feedback" method="post" action=""> <fieldset> <h4 class="request">Contact Information</h4> <div class="left"> <label class="desc">Name<span class="required"> *:</span></label> <?php if (isset($missing) && in_array('name', $missing)) { ?> <span class="warning">Please enter your name</span><?php } ?> <input name="name" id="name" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['name']).'"';} ?> /> <br /> <label class="desc">Company Name:</label> <?php if (isset($missing) && in_array('company', $missing)) { ?> <?php } ?> <input name="company" id="company" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['company']).'"';} ?> /> <br /> <label class="desc">Email Address:</label> <?php if (isset($missing) && in_array('email', $missing)) { ?> <?php } ?> <input name="email" id="email" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email']).'"';} ?> /> <br /> </div> <div class="right"> <label class="desc">Phone<span class="required"> *:</span></label> <?php if (isset($missing) && in_array('phone', $missing)) { ?> <span class="warning">Please enter your phone number</span><?php } ?> <input name="phone" id="phone" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['phone']).'"';} ?> /> <br /> <label class="desc">Fax:</label> <?php if (isset($missing) && in_array('fax', $missing)) { ?> <?php } ?> <input name="fax" id="fax" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['fax']).'"';} ?> /> <br /> <label class="desc">Cell:</label> <?php if (isset($missing) && in_array('cell', $missing)) { ?> <?php } ?> <input name="cell" id="cell" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['cell']).'"';} ?> /> <br /> </div> <h4 class="request">Departures and Arrivals</h4> <div class="left"> <label class="desc">Departure City / Airport<span class="required"> *:</span></label> <?php if (isset($missing) && in_array('departurecity', $missing)) { ?> <span class="warning">Please enter your departure city</span><?php } ?> <input name="departurecity" id="departurecity" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['departurecity']).'"';} ?> /> <br /> <label class="desc">Alternate Departure City / Airport:</label> <?php if (isset($missing) && in_array('alternatedeparture', $missing)) { ?> <?php } ?> <input name="alternatedeparture" id="alternatedeparture" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['alternatedeparture']).'"';} ?> /> <br /> </div> <div class="right"> <label class="desc">Arrival City / Airport<span class="required"> *:</span></label> <?php if (isset($missing) && in_array('arrivalcity', $missing)) { ?> <span class="warning">Please enter your arrival city</span><?php } ?> <input name="arrivalcity" id="arrivalcity" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['arrivalcity']).'"';} ?> /> <br /> <label class="desc">Alternate Arrival City / Airport:</label> <?php if (isset($missing) && in_array('alternatearrival', $missing)) { ?> <?php } ?> <input name="alternatearrival" id="alternatearrival" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['alternatearrival']).'"';} ?> /> <br /> </div> <div class="left"> <label class="desc">Departure Date<span class="required"> *:</span></label> <?php if (isset($missing) && in_array('departuredate', $missing)) { ?> <span class="warning">Please enter your departure date</span><?php } ?> <input name="departuredate" id="departuredate" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['departuredate']).'"';} ?> /><div class="floatRight"><a href="javascript:NewCal('departuredate','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" alt="Pick a date" /></a></div> <br /> <div class="check"><em>Flexible:</em> <span class="radio">Yes <input type="radio" name="flexdeparturedate1" id="flexdeparturedate1" value="yes" /></span><span class="radio">No <input type="radio" name="flexdeparturedate2" id="flexdeparturedate2" value="no" /></span> <span class="radio">Earlier <input type="checkbox" name="earliertime1" id="earliertime1" value="Earlier" /></span><span class="radio">Later <input type="checkbox" name="latertime1" id="latertime1" value="Later" /></span></div> <br /> </div> <div class="right"> <label class="desc">Departure Time<span class="required"> *:</span></label> <span class="warning">Please enter your return date</span> <select name="departuretime"> <option value="NULL">Please choose a departure time</option> <option value="12 AM">12 AM</option> <option value="1 AM">1 AM</option> <option value="2 AM">2 AM</option> <option value="3 AM">3 AM</option> <option value="4 AM">4 AM</option> <option value="5 AM">5 AM</option> <option value="6 AM">6 AM</option> <option value="7 AM">7 AM</option> <option value="8 AM">8 AM</option> <option value="9 AM">9 AM</option> <option value="10 AM">10 AM</option> <option value="11 AM">11 AM</option> <option value="12 PM">12 PM</option> <option value="1 PM">1 PM</option> <option value="2 PM">2 PM</option> <option value="3 PM">3 PM</option> <option value="4 PM">4 PM</option> <option value="5 PM">5 PM</option> <option value="6 PM">6 PM</option> <option value="7 PM">7 PM</option> <option value="8 PM">8 PM</option> <option value="9 PM">9 PM</option> <option value="10 PM">10 PM</option> <option value="11 PM">11 PM</option> </select> <br /> <div class="check"><em>Flexible:</em> <span class="radio">Yes <input type="radio" name="flexdeparturetime1" id="flexdeparturetime1" value="yes" /></span><span class="radio">No <input type="radio" name="flexdeparturetime2" id="flexdeparturetime2" value="no" /></span> <span class="radio">Earlier <input type="checkbox" name="earliertime2" id="earliertime2" value="Earlier" /></span><span class="radio">Later <input type="checkbox" name="latertime2" id="latertime2" value="Later" /></span></div> <br /> </div> <div class="left"> <label class="desc">Return Date<span class="required"> *:</span></label> <?php if (isset($missing) && in_array('returndate', $missing)) { ?> <span class="warning">Please enter your return date</span><?php } ?> <input name="returndate" id="returndate" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['returndate']).'"';} ?> /><div class="floatRight"><a href="javascript:NewCal('returndate','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" alt="Pick a date" /></a></div> <br /> <div class="check"><em>Flexible:</em> <span class="radio">Yes <input type="radio" name="flexreturndate1" id="flexreturndate1" value="yes" /></span><span class="radio">No <input type="radio" name="flexreturndate2" id="flexreturndate2" value="no" /></span> <span class="radio">Earlier <input type="checkbox" name="earliertime3" id="earliertime3" value="Earlier" /></span><span class="radio">Later <input type="checkbox" name="latertime3" id="latertime3" value="Later" /></span></div> <br /> </div> <div class="right"> <label class="desc">Return Time<span class="required"> *:</span></label> <span class="warning">Please enter your return date</span> <select name="returntime"> <option value="NULL">Please choose a return time</option> <option value="12 AM">12 AM</option> <option value="1 AM">1 AM</option> <option value="2 AM">2 AM</option> <option value="3 AM">3 AM</option> <option value="4 AM">4 AM</option> <option value="5 AM">5 AM</option> <option value="6 AM">6 AM</option> <option value="7 AM">7 AM</option> <option value="8 AM">8 AM</option> <option value="9 AM">9 AM</option> <option value="10 AM">10 AM</option> <option value="11 AM">11 AM</option> <option value="12 PM">12 PM</option> <option value="1 PM">1 PM</option> <option value="2 PM">2 PM</option> <option value="3 PM">3 PM</option> <option value="4 PM">4 PM</option> <option value="5 PM">5 PM</option> <option value="6 PM">6 PM</option> <option value="7 PM">7 PM</option> <option value="8 PM">8 PM</option> <option value="9 PM">9 PM</option> <option value="10 PM">10 PM</option> <option value="11 PM">11 PM</option> </select> <br /> <div class="check"><em>Flexible:</em> <span class="radio">Yes <input type="radio" name="flexreturntime1" value="yes" /></span><span class="radio">No <input type="radio" name="flexreturntime2" value="no" /></span> <span class="radio">Earlier <input type="checkbox" name="earliertime4" id="earliertime4" value="Earlier" /></span><span class="radio">Later <input type="checkbox" name="latertime4" id="latertime4" value="Later" /></span></div> <br /> </div> <h4 class="request">Other Information</h4> <div class="left"> <div class="check">Medical Insurance<span class="required"> *:</span> <!--<span class="warning">Please enter your choice</span>--> <span class="radio">Yes <input type="radio" name="insurance" id="medical1" value="yes" /></span><span class="radio">No <input type="radio" name="insurance" id="medical2" value="no" /></span></div> <br /> <div class="check">Hotel Required<span class="required"> *:</span> <!--<span class="warning">Please enter your choice</span>--> <span class="radio">Yes <input type="radio" name="hotel" id="hotel1" value="yes" /></span><span class="radio">No <input type="radio" name="hotel" id="hotel2" value="no" /></span></div> <br /> <label class="desc">Preferred Hotel:</label> <?php if (isset($missing) && in_array('preferredhotel', $missing)) { ?> <?php } ?> <input name="preferredhotel" id="preferredhotel" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['preferredhotel']).'"';} ?> /> <br /> <label class="desc">Special Rates<span class="subText"> (If applicable):</span></label> <?php if (isset($missing) && in_array('specialrates', $missing)) { ?> <?php } ?> <input name="specialrates" id="specialrates" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['specialrates']).'"';} ?> /> <br /> <div class="check">Car Rental<span class="required"> *:</span> <span class="radio">Yes <input type="radio" name="rental1" id="rental1" value="yes" /></span><span class="radio">No <input type="radio" name="rental2" id="rental2" value="no" /></span></div> <br /> <label class="desc">Preferred Dealer<span class="subText"> (Budget, Hertz, etc.):</span></label> <?php if (isset($missing) && in_array('preferreddealer', $missing)) { ?> <?php } ?> <input name="preferreddealer" id="preferreddealer" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['preferreddealer']).'"';} ?> /> <br /> </div> <div class="right"> <label class="desc">Special Notes:</label> <?php if (isset($missing) && in_array('specialnotes', $missing)) { ?> <?php } ?> <textarea name="specialnotes" id="specialnotes" class="inputRequest" cols="32" rows="19"><?php if (isset($missing)) { echo htmlentities($_POST['specialnotes']); } ?></textarea> <br /> </div> <div class="process"> <h4 class="request">Please let us know if you have any further requests or comments :</h4> <label class="desc"></label> <?php if (isset($missing) && in_array('furtherdetails', $missing)) { ?> <span class="warning">Please enter your project details</span><?php } ?> <textarea name="furtherdetails" id="furtherdetails" class="textareaRequest" cols="32" rows="6"><?php if (isset($missing)) { echo htmlentities($_POST['furtherdetails']); } ?></textarea> <br /> </div> <div class="process"> <p>Click below to process your request. We will contact you asap when we have put together a package for your vacation / getaway.</p> <div class="formAction"> <input name="send" id="send" type="submit" value="Submit" class="formButton" /> <input type="reset" value="Reset" class="formButton" /> <div class="top"><a href="#top" title="Click to return to the top of this page">TOP</a></div> </div> </div> </fieldset> </form> </div> </div> <div id="sideCol"> <?php include("includes/specials.php"); ?> <?php include("includes/sidecolaffiliates.php"); ?> </div> </div> <?php include("includes/footeraffiliates.php"); ?> </div> </div> </div> <div id="footer"> <?php include("includes/footer_menu.php"); ?> </div> </div> </body> </html> I hope someone can assist me with this issue and I thank you in advance for your time. Link to comment https://forums.phpfreaks.com/topic/127048-sticky-form-fields/ Share on other sites More sharing options...
Andy-H Posted October 5, 2008 Share Posted October 5, 2008 code too long... Link to comment https://forums.phpfreaks.com/topic/127048-sticky-form-fields/#findComment-657325 Share on other sites More sharing options...
richardjh Posted October 5, 2008 Share Posted October 5, 2008 I'm not at all good with php but I know that to create a sticky form you need to echo the variable in the forms "value" field. So this: <input name="email" id="email" type="text" class="inputRequest" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email']).'"';} ?> /> Could be changed to: <input name="email" id="email" type="text" value="<?php echo $_POST['email'] ?> /> I could be wrong (usually am) but I was actually doing the same thing the other night (fiddling with sticky forms) and I finally got it to work using this way. hope this helps a bit Link to comment https://forums.phpfreaks.com/topic/127048-sticky-form-fields/#findComment-657478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.