View Full Version : 'contact me' page
riyadh
02-16-2007, 06:51 PM
i wrote a 'contact me' page through which ppl can contact me if they wish. i want to make sure tht if the user doesn't fill anyone of the required fields, red text will appear will appear underneath the fields telling the user to fill them in. and can someone also tell me if i have done anything wrong in the code? the code is given below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<body>
<?php
$name = $_POST['name'];
$sub = $_POST['sub'];
$address = $_POST['email'];
$msg = $_POST['msg'];
$ip = $_SERVER['REMOTE_ADDR'];
$mess = "
Subject: $sub \n
Message: $msg \n
From: $address \n
IP: $ip \n
";
if ( (!$name)||(!$sub)||(!$msg) ){
echo "Please fix the following:<BR>";
if(!$name){
echo "Please fill in your name<BR>";
}
if(!$sub){
echo "Please fill in the subject<BR>";
}
if(!$msg){
echo "Please fill in the message<BR><BR>";
}
echo('
<form action="contact.php" method="post">
Name: <input type="text" name="name" class="input"><BR>
Subject: <input type="text" name="sub" class="input"><BR>
E-mail <input type="text" name="email" class="input"><BR>
Message:
<textarea name="msg" rows="7" cols="50" class="input"></textarea>
<input type="submit" value="Send" class="button">
</form>";
} else {
mail("myaddress@mydomain.com", "Subject: $sub", $mess, "From: $name <$address>");
if(mail) {
echo "Thank you! Please wait up to 48 hours for a reply.";
} else {
echo "The message could not be sent. Please try again later.";
}
}
?>');
</body></html>
thetestingsite
02-16-2007, 07:03 PM
The only things I could see by just glancing at the code is below in red. You will also be able to see one other problem that I took out by comparing the codes.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<body>
<?php
$name = $_POST['name'];
$sub = $_POST['sub'];
$address = $_POST['email'];
$msg = $_POST['msg'];
$ip = $_SERVER['REMOTE_ADDR'];
$mess = "
Subject: $sub \n
Message: $msg \n
From: $address \n
IP: $ip \n
";
if ( (!$name)||(!$sub)||(!$msg) ){
echo "Please fix the following:<BR>";
if(!$name){
echo "Please fill in your name<BR>";
}
if(!$sub){
echo "Please fill in the subject<BR>";
}
if(!$msg){
echo "Please fill in the message<BR><BR>";
}
echo('
<form action="contact.php" method="post">
Name: <input type="text" name="name" class="input"><BR>
Subject: <input type="text" name="sub" class="input"><BR>
E-mail <input type="text" name="email" class="input"><BR>
Message:
<textarea name="msg" rows="7" cols="50" class="input"></textarea>
<input type="submit" value="Send" class="button">
</form>');
} else {
mail("myaddress@mydomain.com", "Subject: $sub", $mess, "From: $name <$address>");
if(mail) {
echo "Thank you! Please wait up to 48 hours for a reply.";
} else {
echo "The message could not be sent. Please try again later.";
}
}
?>
</body>
</html>
Hope this helps.
Strangeplant
02-16-2007, 08:17 PM
You probably want to use sessions. Then transfer your input data to sessions variables so that if there is an incomplete entry, you can set error messages to instruct what to fill in and fill the fields with the previous data input so the user doesn't have to retype everything. And then you cause the program to redirect to itself if there is an incomplete entry, else send the data and announce that its been sent. You can use a hidden variable so you can test if the data is complete on reentry to finish.
Use functions to generate the basic parts of the html code you need and it will simplify the understanding of the flow.
That's the way I do it, and it looks great.
Shotgun Ninja
02-20-2007, 01:55 PM
You probably want to use sessions. Then transfer your input data to sessions variables so that if there is an incomplete entry, you can set error messages to instruct what to fill in and fill the fields with the previous data input so the user doesn't have to retype everything. And then you cause the program to redirect to itself if there is an incomplete entry, else send the data and announce that its been sent. You can use a hidden variable so you can test if the data is complete on reentry to finish.
Use functions to generate the basic parts of the html code you need and it will simplify the understanding of the flow.
That's the way I do it, and it looks great.
:confused:
mburt
02-20-2007, 02:03 PM
When test pointed out that code, he meant that echo isn't a bracket function, see here:
echo '
<form action="contact.php" method="post">
Name: <input type="text" name="name" class="input"><BR>
Subject: <input type="text" name="sub" class="input"><BR>
E-mail <input type="text" name="email" class="input"><BR>
Message:
<textarea name="msg" rows="7" cols="50" class="input"></textarea>
<input type="submit" value="Send" class="button">
</form> ';
It stands alone, without brackets. As for what StrangePlant said, all he/she meant was that the data could be stored in sessions and validated.
ilensoft
02-20-2007, 03:39 PM
this is the way you code should look like. You were not careful with the syntaxes used. Differenciate this with yours
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<body>
<?php
$name = $_POST['name'];
$sub = $_POST['sub'];
$address = $_POST['email'];
$msg = $_POST['msg'];
$ip = $_SERVER['REMOTE_ADDR'];
$mess = "
Subject: $sub \n
Message: $msg \n
From: $address \n
IP: $ip \n
";
if ( (!$name)||(!$sub)||(!$msg) ){
echo "Please fix the following:<BR>";
if(!$name){
echo "Please fill in your name<BR>";
}
if(!$sub){
echo "Please fill in the subject<BR>";
}
if(!$msg){
echo "Please fill in the message<BR><BR>";
}
echo('
<form action="contact.php" method="post">
Name: <input type="text" name="name" class="input"><BR>
Subject: <input type="text" name="sub" class="input"><BR>
E-mail <input type="text" name="email" class="input"><BR>
Message:
<textarea name="msg" rows="7" cols="50" class="input"></textarea>
<input type="submit" value="Send" class="button">
</form>');
} else {
mail("myaddress@mydomain.com", "Subject: $sub", $mess, "From: $name <$address>");
if(mail) {
echo "Thank you! Please wait up to 48 hours for a reply.";
} else {
echo "The message could not be sent. Please try again later.";
}
}
?>
</body></html>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.