Forum Moderators: coopster

Message Too Old, No Replies

need help with php scripting

need to validate a form with php

         

fbadyari

12:17 pm on Dec 21, 2010 (gmt 0)

10+ Year Member



can anybody help me with getting a php scripting, i want to add a date selection calender for the arrival & departure , & for adult & child dropdown menu to my existing form. my html page is as below


<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>myname.com</title>
<meta name="distribution" content="Global" >
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
</head><body>
<div id="wrapper">
<div id="logo">
<h1>THANKS</h1>
<p>Extreme Powder </p>
</div>
<div id="nav">
<div id="nav-left">
<ul>
<li><a href="http://www.myname.com">Home</a></li>
<li class="orange"><a href="http://www.myname.com">Contact</a></li>
</ul>
</div>
<div id="nav-right">
<ul>
<li><a href="http://www.myname.com">myname.com</a></li>
<li><a href="http://www.myname.com">myname.com</a></li>
<li><a href="http://www.myname.com">myname.com</a></li>
<li><a href="http://www.myname.com">myname.com</a></li>
</ul>
</div>
</div>
<div id="body">
<div id="left">
<div id="welcome">
<h2 class="guilded"><span>Skiing in </span></h2>
<p>GULMARG ( Powder Skiing )
Skiing in - a wonderful combination of incredible powder skiing and the unique Hospitable culture - Which Makes it one
of the world's Most Adventerous & Memorable skiing experience one can ever have. is located 56-km ( 35 miles ) south west of
, is a mountain shelf which nestles under the protective metre height and 5 km spread of . is a
small isolated hill-village situated in the northern Indian state of at the western extremity of the in a
subsidiary range called the . is also know for the competitive tournament of skiing in festive season like Christmas and
Easter.Due to its geographic location ets some of the heaviest snowfalls in the and it has earned the distinction of
being the best ski resort in the . Skiing was first introduced to ski club in 1927 although it wasn't until 5-6 years ago when hotlist!
</p>
</div>
<div id="chef">
<h2>Why choose .</h2>
<p>With a very little population of local skiers, there are always many unmarked trials for every body.
Worlds highest offering breathtaking Views ( Compared to Heliski ).
Safety group environment with Expert Mountain Guides.
Fun filled most Memorable Adventure Tour to bring you & yours friends back again & again.</p>
<p class="more"><a href="http://www.myname.com">More...</a></p>
</div>
</div>
<div id="right">
<div id="booking">
<h2>Instant booking- </h2>
<form action="" method="get" accept-charset="utf-8">
<table border="0" cellspacing="2" cellpadding="0">

</table>
</form>
</div>
<div id="menu">
<h2>&nbsp&nbspSpecial Hotel Deals</h2>
<p>Get special hotel deals with skiing tours<br><br> <a href="http://www.myname.com">Hotels</a><br><br>
<a href="http://www.myname.com"> Hotels</a><br><br>
<a href="http://www.myname.com">Car / Coach Rental</a></p>
<form action="" method="get" accept-charset="utf-8">
</form>
</div><br>
<div id="booking">
<h2>Online booking</h2>
<FORM METHOD="POST" action="contact.php">
<table align=center>
<tr><td>Name: </td><td> <input type=text name="yourname" size=20></td></tr><tr>
<tr><td>Email:</td><td> <input type=text name="email" size=20></td></tr>
<tr><td>Phone:</td><td> <input type=text name="phone" size=20></td></tr>
<tr><td>Arrival:</td><td> <input type=text name="datum1" ></td></tr>
<tr><td>Departure:</td><td> <input type=text name="datum2" ></td></tr>
<tr><td>Adults:</td><td>
<select name="adults">
<option value="">01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
</select>
Child:
<select name="adults">
<option value="">01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
</select>
</td></tr>
<tr><td>Comments:</td><td><textarea name="comments" cols=17 rows=3></textarea></td></tr>
<tr> <td colspan=2 align=center> <input type=submit value="Submit">
<input type=reset value="Reset"> </FORM></td></tr>
</table>
</div>

</div>
<div class="clear"> </div>
<div id="footer">
<ul>
<li><a href="http://www.myname.com">Home</a> | </li>
<li><a href="http://www.myname.com">Avlanche Safety</a> | </li>
<li><a href="http://www.myname.com">Snowboarding</a> | </li>
<li><a href="http://www.myname.com">Powder Guides</a> | </li>
<li><a href="http://www.myname.com">Skiing Training</a> | </li>
<li><a href="http://www.myname.com">Contact</a></li>
</ul>
<p>copyright &copy; myname.com</p>
</div>
</div>
</div>
</body>
</html>


below is the php which i copied from the net & works good for sending mail but , i tried some calenders taken from the net in javascript, but i was unable to make them work in my form till i was frustated.



below is the php code


<?php
/* Set e-mail recipient */
$myemail = "email@email.com";

/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$email = check_input($_POST['email']);
$phone = check_input($_POST['phone']);
$arrival = check_input($_POST['arrival']);
$departure = check_input($_POST['departure']);
$adults_num = check_input($_POST['adults']);
$children = check_input($_POST['children']);
$comments = check_input($_POST['comments'], "Write your comments");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}

/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}

/* Let's prepare the message for the e-mail */
$message = "Hello!

Query submitted through :

Name: $yourname
E-mail: $email
Phone: $phone
Arrival: $arrival
Departure: $departure
Adults: $adults
Child: $children

Like the website? $likeit
How did he/she find it? $adults_num

Comments:
$comments

End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<b>Please go back to the form page and correct the following error:</b><br />
<?php echo $myError; ?>

</body>
</html>
<?php
exit();
}
?>

coopster

8:06 pm on Dec 30, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you struggling with the JavaScript? Or the PHP server-side processing? That's a lot of code and most folks don't want to or don't have the time to sift through that much information. If you could narrow it down it bit that may help get some discussion and direction.

drent

9:19 pm on Dec 31, 2010 (gmt 0)

10+ Year Member



There is a book called the "php cookbook". Would this chapter fix it for you?

Recipe 9.18. Creating Drop-Down Menus Based on the Current Date

You can google the above to see it on the web, or get a copy of the book.