Jump to content

contact form if statement please help!


lialight

Recommended Posts

I am not sure where I am going wrong here... I have had two other people look at my code an they said it looked fine and they had no idea what is wrong with it.... please someone help me!

The part I am having trouble with is that there is an email field and a phone field and the user is required to enter either the phone or the e-mail but they do not have to enter both.
[code]

<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "HH1";
$name_field = $_POST['visitor'];
$email_field = $_POST['visitormail'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$MemberID = $_POST['MemberID'];
$MiddleInitial = $_POST['MiddleInitial'];
$MemberAddress = $_POST['MemberAddress'];
$MemberAddress2 = $_POST['MemberAddress2'];
$MemberPhone = $_POST['MemberPhone'];
$DoctorFirstName = $_POST['DoctorFirstName'];
$DoctorLastName = $_POST['DoctorLastName'];
$DoctorAddress = $_POST['DoctorAddress'];
$DoctorAddress2 = $_POST['DoctorAddress2'];
$DoctorCity = $_POST['DoctorCity'];
$DoctorState = $_POST['DoctorState'];
$DoctorZip = $_POST['DoctorZip'];
$DoctorAddress = $_POST['DoctorAddress'] ;
$DoctorAddress2 = $_POST['DoctorAddress2'] ;
$HealthPlan = $_POST['HealthPlan'];
$radio = $_POST['radio'];
}

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
if(empty($visitor) && empty($visitormail)) {
echo "Use Back fill in e-mail or phone #\n";
}
if(empty($visitor)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">First Name</font></b>\n";

}

if(empty($LastName)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Last Name</font></b>\n";

}

if(empty($MemberID)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member ID</font></b>\n";

}

if(empty($MemberAddress)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member Address.</font></b>\n";

}

if(empty($City)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member City.</font></b><br><br>\n";

}

if(empty($State)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member State.</font></b><br><br>\n";

}

if(empty($DoctorFirstName)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor First Name.</font></b><br><br>\n";
echo "<br><br>";

}

if(empty($DoctorLastName)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor Last Name.</font></b><br><br>\n";

}

if(empty($DoctorAddress)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor Address.</font></b><br><br>\n";
echo "<br><br>";

}

if(empty($DoctorCity)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor City.</font></b><br><br>\n";

}

if(empty($DoctorState)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor State.</font></b><br><br>\n";

}

if(empty($HealthPlan)) {
echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Health Plan.</font></b><br><br>\n";

}
$message = " Member Name: $visitor \n
Last Name: $LastName \n
Middle initial: $MiddleInitial \n
MemberID: $MemberID \n
City: $City \n
State: $State \n
Zip: $Zip \n
Address: $MemberAddress \n
Address2: $MemberAddress2 \n
Phone: $MemberPhone \n
Email: $visitormail \n
Are they a member?: $radio \n
Non member name: $NonMemberName \n
Non member relationship: $NonMemberRelationship \n
Doctor First Name: $DoctorFirstName \n
Last Name: $DoctorLastName \n
Address: $DoctorAddress \n
Address2: $DoctorAddress2 \n
City: $DoctorCity \n
Zip: $DoctorZip \n
State: $DoctorState \n
Address: $DoctorAddress \n
Address2: $DoctorAddress2 \n
Health Plan: $HealthPlan \n";

$from = "From: [email protected]\r\n";


mail("[email protected]", $subject, $message, $from);

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/33302-contact-form-if-statement-please-help/
Share on other sites

I agree with emehrkay, you need to sanitize your data, but you also need to set your variables properly.  I noticed that you are testing variables that have not been set.

[code]if(![b]$visitormail[/b] == "" && (!strstr([b]$visitormail[/b],"@") || !strstr([b]$visitormail[/b],".")))
.....
if(empty([b]$visitor[/b]) && empty([b]$visitormail[/b])) {
.....
if(empty([b]$visitor[/b])) {
[/code]

Those values will only work if you have register_globals set in your php.ini file, which is bad practice for any piece of production code.  Try inserting the following code just before you test your variables.
[code]
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.