Forum Moderators: coopster

Message Too Old, No Replies

php code requirement

php code requirement

         

fbadyari

5:46 am on Dec 23, 2010 (gmt 0)

10+ Year Member



I want to add array option / a calender for arrival / departure & if the person does not want write his email/ name , want to sent him back on the form page

<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="arrival" ></td></tr>
<tr><td>Departure:</td><td> <input type=text name="departure" ></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>


the code is given below

<?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();
}
?>

rocknbil

5:52 pm on Dec 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't say "go back." All you need to do is put your form inside the show_error function. Fixed. :-)