PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<html>
<head>
</head>
<body>
<?php
/* grabs the POST variables and puts them into variables that we can use */
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$website=$_POST['website'];
$countryCode=$_POST['countryCode'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$postCode=$_POST['postCode'];
$inquiring=$_POST['inquiring'];
//---------VALIDATION---24----->
if($firstName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your first name\n";//----> ERROR if no input
}
if($lastName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your last name\n";//----> ERROR if no input
}
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail address\n";//----> ERROR if no input
}
if($phone){//----> CHECK input
}
else{
$error.="Please, go back and fill out your phone number\n";//----> ERROR if no input
}
if($address){//----> CHECK input
}
else{
$error.="Please, go back and fill out your mailing address\n";//----> ERROR if no input
}
if($city){//----> CHECK input
}
else{
$error.="Please, go back and fill out your city name\n";//----> ERROR if no input
}
if($postCode){//----> CHECK input
}
else{
$error.="Please, go back and fill out your post code\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Post Code: ".$postCode."\n\n--------INFO--------\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
$toAddress="gappamurphy@hotmail.com";
$subject="Romeld Australia";
$recipientSubject="Romeld Australia";
$receiptMessage="Thank you ".$firstName." for inquiring about Romeld Australia!\n\n\nHere is what you submitted to us:\n\n"
."--------CONTACT--------\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."E-mail: ".$email."\n"
."Website: ".$website."\n\n--------PHONE--------\n"
."Phone: ".$countryCode." ".$phone."\n"
."Extension: ".$phoneExt."\n"
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
."Street Address: ".$address."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Country: ".$country."\n"
."Post Code: ".$postCode."\n\n--------INFO--------\n"
."Inquiring About: ".$inquiring."\n"
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
}
else{
print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - \n";
print "$error\n";
print "\n";
print "\n";
print "Please use your "Back" button to return to the form to correct the omissions. Thank you.\n";
}
?>
</body>
</html>
Heres the full script fixed... i think :\ Sorry im on th elibrary computers and they dont allow me to access my FTP not even in IE , so sorry if it dont work. I just used the example that tim said and just fixed the rest. Hope it works
<html>
<head>
</head>
<body>
<?php
/* grabs the POST variables and puts them into variables that we can use */
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$website=$_POST['website'];
$countryCode=$_POST['countryCode'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$postCode=$_POST['postCode'];
$inquiring=$_POST['inquiring'];
//---------VALIDATION---24----->
if($firstName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your first name\n";//----> ERROR if no input
}
if($lastName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your last name\n";//----> ERROR if no input
}
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail address\n";//----> ERROR if no input
}
if($phone){//----> CHECK input
}
else{
$error.="Please, go back and fill out your phone number\n";//----> ERROR if no input
}
if($address){//----> CHECK input
}
else{
$error.="Please, go back and fill out your mailing address\n";//----> ERROR if no input
}
if($city){//----> CHECK input
}
else{
$error.="Please, go back and fill out your city name\n";//----> ERROR if no input
}
if($postCode){//----> CHECK input
}
else{
$error.="Please, go back and fill out your post code\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n";
."First Name: ".$firstName."\n";
."Last Name: ".$lastName."\n";
."Company: ".$company."\n";
."E-mail: ".$email."\n";
."Website: ".$website."\n\n--------PHONE--------\n";
."Phone: ".$countryCode." ".$phone."\n";
."Extension: ".$phoneExt."\n";
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n";
."Street Address: ".$address."\n";
."City: ".$city."\n";
."State: ".$state."\n";
."Country: ".$country."\n";
."Post Code: ".$postCode."\n\n--------INFO--------\n";
."Inquiring About: ".$inquiring."\n";
//----------------------------------
$toAddress="gappamurphy@hotmail.com";
$subject="Romeld Australia";
$recipientSubject="Romeld Australia";
$receiptMessage="Thank you ".$firstName." for inquiring about Romeld Australia!\n\n\nHere is what you submitted to us:\n\n";
."--------CONTACT--------\n";
."First Name: ".$firstName."\n";
."Last Name: ".$lastName."\n";
."Company: ".$company."\n";
."E-mail: ".$email."\n";
."Website: ".$website."\n\n--------PHONE--------\n";
."Phone: ".$countryCode." ".$phone."\n";
."Extension: ".$phoneExt."\n";
."Mobile: ".$mobile."\n\n--------ADDRESS--------\n";
."Street Address: ".$address."\n";
."City: ".$city."\n";
."State: ".$state."\n";
."Country: ".$country."\n";
."Post Code: ".$postCode."\n\n--------INFO--------\n";
."Inquiring About: ".$inquiring."\n";
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
}
else{
print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - \n";
print "$error\n";
print "\n";
print "\n";
print "Please use your "Back" button to return to the form to correct the omissions. Thank you.\n";
}
</body>
</html>
yea, I would agree with raji - clientside validating is usually better. Use javascript to ensure that the form is filled in properly before allowing the user to submit it. a) it takes some work off the server and b) it makes it harder for users to screw it up