PDA

View Full Version : Blank fields in my contact form email?


califjewls
05-04-2011, 04:06 AM
I am having a couple issues, the first is: when I receive my contact form email, not all of the values show. The "comments" and the "budget" results show up perfectly, but the important part(s) such as Name, Address, Email, Phone DO NOT show up in my email.

The second issue Im having is that even though I validated my form using Dreamweaver I can still send a blank form even though I required some of the fields?

Can someone please tell me what I am doing wrong. I copied and pasted the original code from Helpvid.net.

Here is my PHP code:
<?php

/* Email Variables */

$emailSubject = 'contactform!';
$webMaster = 'MY EMAIL IS HERE';


/* Data Variables */

$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];



$body = <<<EOD
<br><hr><br>
Company: $company <br>
Name: $name <br>
Address: $address <br>
Email: $email <br>
Phone: $phone <br>
Comments: $comments <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);


// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

/* Results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="6;URL=MY URL IS HERE">
<style type="text/css">
<!--
body {
background-color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #5083a4;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}

-->
</style>
</head>
<div align="center">Your message has been sent!
</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>

califjewls
05-04-2011, 04:08 AM
Here is my form:

<form id="form1" name="form1" method="post" action="contactform.php">


<table width="97%">
<tr>
<td width="145" align="left" valign="top" class="body" id="Company"><strong>Company:</strong></td>
<td width="280" align="left" valign="top"><input name="Company" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Contact"><strong>Full Name:</strong></td>
<td align="left" valign="top"><input name="Name" type="text" id="Name" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Address"><strong>Address: </strong></td>
<td align="left" valign="top"><input name="Address" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Phone"><strong> Phone: </strong></td>
<td align="left" valign="top"><input name="Phone" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Email"><strong> Email: </strong></td>
<td align="left" valign="top"><input name="Email" type="text" id="Email" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Comments"><strong> Questions / Comments: </strong></td>
<td align="left" valign="top"><textarea name="comments" cols="25" rows="6" id="comments"></textarea></td>
</tr>
<tr>
<td></td>
<td><input name="submit" type="submit" class="button" onclick="MM_validateForm('Name','','R','Email','','RisEmail ','comments','','R');return document.MM_returnValue" value="Send Now" /></td>
</tr>
</table>
</form>

edbr
05-04-2011, 04:10 AM
post your form

edbr
05-04-2011, 04:11 AM
and

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
says all fields can be empty

califjewls
05-04-2011, 04:15 AM
and

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
says all fields can be empty
Thank you, I just deleted that, but I had just added it. I had blank fields with and without that portion of the code.

edbr
05-04-2011, 04:17 AM
get to that later just post your form code for now

califjewls
05-04-2011, 04:26 AM
get to that later just post your form code for now

I posted it up above but here it is:

<form id="form1" name="form1" method="post" action="contactform.php">

<table width="97%">
<tr>
<td width="145" align="left" valign="top" class="body" id="Company"><strong>Company:</strong></td>
<td width="280" align="left" valign="top"><input name="Company" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Contact"><strong>Full Name:</strong></td>
<td align="left" valign="top"><input name="Name" type="text" id="Name" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Address"><strong>Address: </strong></td>
<td align="left" valign="top"><input name="Address" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Phone"><strong> Phone: </strong></td>
<td align="left" valign="top"><input name="Phone" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Email"><strong> Email: </strong></td>
<td align="left" valign="top"><input name="Email" type="text" id="Email" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Comments"><strong> Questions / Comments: </strong></td>
<td align="left" valign="top"><textarea name="comments" cols="25" rows="6" id="comments"></textarea></td>
</tr>
<tr>
<td></td>
<td><input name="submit" type="submit" class="button" onclick="MM_validateForm('Name','','R','Email','','RisEmail ','comments','','R');return document.MM_returnValue" value="Send Now" /></td>
</tr>
</table>
</form>

edbr
05-04-2011, 04:32 AM
ha missed it.
you have miss named your $_Post variables

ie Address not address Phone not phone they must match the firld names

califjewls
05-04-2011, 04:32 AM
These are the results I receive in my email: (even though ALL fields had been completed)

Company:
Name:
Address:
Email:
Phone:
Comments: Testing, Testing, Testing

edbr
05-04-2011, 04:32 AM
do you want all fields required?

califjewls
05-04-2011, 04:45 AM
do you want all fields required?

I don't need address and company, but would like everything else.

califjewls
05-04-2011, 04:53 AM
That worked perfectly, can't believe it was that simple, thank you so much!

All I need is the validation portion now?

califjewls
05-04-2011, 04:55 AM
I also have a second form within my site that I would like ALL fields required, should I use that code I added previously? Only use it correctly? lol

edbr
05-04-2011, 04:59 AM
try this , but i havent tested, and am tending to screw up today so post back and ill look later if not ok


/* Email Variables */

$emailSubject = 'contactform!';
$webMaster = 'MY EMAIL IS HERE';


/* Data Variables */

$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];



$body = <<<EOD
<br><hr><br>
Company: $company <br>
Name: $name <br>
Address: $address <br>
Email: $email <br>
Phone: $phone <br>
Comments: $comments <br>
EOD;

$headers = "From: $email\r\n";


if ($name || $company || $phone ||$comments == '')
{echo "please fill out required field";die;}


$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);


// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

/* Results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="6;URL=MY URL IS HERE">
<style type="text/css">
<!--
body {
background-color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #5083a4;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}

-->
</style>
</head>
<div align="center">Your message has been sent!
</div>
</div>
</body>
</html>
EOD;
echo "$theResults";

califjewls
05-04-2011, 05:17 AM
try this , but i havent tested, and am tending to screw up today so post back and ill look later if not ok



if ($name || $company || $phone ||$comments == '')
{echo "please fill out required field";die;}


That did it!! Yay! Thank you so much for your super quick reply and all your help, sooooo glad I found this forum, I'm sure I'll need more help in the future!!

Julie :)

edbr
05-04-2011, 05:21 AM
no problem

edbr
05-04-2011, 05:41 AM
you could also use javascript validation, it will not be secureas it can be by passed by turning off javascript in the browser but picking up errors before the serverside validation can be ciewed as a form helper for genuine visitors

califjewls
05-04-2011, 05:47 AM
Ok, now I went to add this same code to my 2nd form a quote form and now neither form works properly? I fill in each field and it just gives me the error message to fill out required fields??? The contact form worked fine 2 or 3 times....grrr

califjewls
05-04-2011, 05:50 AM
Here is second form:
<form id="form2" name="form2" method="post" action="quoteform.php">
<table width="97%">
<tr>
<td width="145" align="left" valign="top" class="body" id="Company"><strong>Company:</strong></td>
<td width="280" align="left" valign="top"><input name="company" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Contact"><strong>Full Name:</strong></td>
<td align="left" valign="top"><input name="name" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Address"><strong>Address: </strong></td>
<td align="left" valign="top"><input name="address" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Phone"><strong> Phone: </strong></td>
<td align="left" valign="top"><input name="phone" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Email"><strong> Email: </strong></td>
<td align="left" valign="top"><input name="email" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Budget"><strong> Project Budget </strong></td>
<td align="left" valign="top"><input name="budget" type="text" size="30" /></td>
</tr>
<tr>
<td align="left" valign="top" class="body" id="Comments"><strong> Questions / Comments: </strong></td>
<td align="left" valign="top"><textarea name="comments" cols="25" rows="6"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" class="button" value="Send Now" /></td>
</tr>
</table>
</form>

califjewls
05-04-2011, 05:51 AM
PHP:

<?php

/* Email Variables */

$emailSubject = 'quoteform!';
$webMaster = 'MY EMAIL';


/* Data Variables */

$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$budget = $_POST['budget'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];



$body = <<<EOD
<br><hr><br>
Company: $company <br>
Name: $name <br>
Address: $address <br>
Email: $email <br>
Budget: $budget <br>
Phone: $phone <br>

Comments: $comments <br>
EOD;

$headers = "From: $email\r\n";

if ($company || $name || $email || $budget || $phone ||$comments == '')
{echo "Please click back on your browser to complete the required field(s).";die;}

$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);

/* Results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="5;URL=http://MY URL">
<style type="text/css">
<!--
body {
background-color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #5083a4;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}

-->
</style>
</head>
<div align="center">Your information has been sent!<br>
You will return to Web Design by Jewlz in a few seconds!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>

edbr
05-04-2011, 05:51 AM
different field values maybe?

califjewls
05-04-2011, 05:58 AM
different field values maybe?
Meaning? I need to name them differently on each form?

edbr
05-04-2011, 06:07 AM
no if the field names are the same they will be ok but if different tou need to change the mailing script especially for that form

califjewls
05-04-2011, 06:11 AM
no if the field names are the same they will be ok but if different tou need to change the mailing script especially for that form

the mailing script? as in email address? Im sorry, Im confused..:(

edbr
05-04-2011, 06:31 AM
the script ?page that sends your mail ,

the form sends info in the form of $_POST variables in your script they are used to form the message

califjewls
05-04-2011, 06:37 AM
Can you give me an example of what it should look like? I appreciate your help!

edbr
05-04-2011, 06:58 AM
this is the script that sens the mail


/* Email Variables */

$emailSubject = 'contactform!';
$webMaster = 'MY EMAIL IS HERE';


/* Data Variables */

$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];



$body = <<<EOD
<br><hr><br>
Company: $company <br>
Name: $name <br>
Address: $address <br>
Email: $email <br>
Phone: $phone <br>
Comments: $comments <br>
EOD;

$headers = "From: $email\r\n";


if ($name || $company || $phone ||$comments == '')
{echo "please fill out required field";die;}


$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);


// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

/* Results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="6;URL=MY URL IS HERE">
<style type="text/css">
<!--
body {
background-color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #5083a4;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}

-->
</style>
</head>
<div align="center">Your message has been sent!
</div>
</div>
</body>
</html>
EOD;
echo "$theResults";

it collects the following $_post variables sent from a form


$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];


if they are diferen it will throw out the validation i added for yopu

califjewls
05-04-2011, 07:03 AM
Ok so even though I have 2 separate .php files (contactform.php, quoteform.php), they have to have the same fields within the same website? I thought you could have several different forms within 1 website. I could be totally misunderstanding though....ughh

califjewls
05-04-2011, 07:19 AM
Both forms are identical now except for the .php file (contactform.php, quoteform.php), and neither of them will actually send, it just continues to send me the the error message to fill in the fields, even though all the fields are filled in...I don't know where it went wrong, because the contact form was actually working for 5 mins...lol

edbr
05-04-2011, 07:30 AM
scripts either work or not , take out the validation part and test

califjewls
05-04-2011, 07:42 AM
Yes that worked, I removed:

if ($name || $company || $phone ||$comments == '')
{echo "please fill out required field";die;}

and they both work now...hmmm

califjewls
05-04-2011, 07:56 AM
I'd still like to have the name, email, phone and comments required fields. I tried using Dreamweaver to solve this but it didn't work.

I tried highlighting my form "submit" image in Dreamweaver, window>behaviors>+>validate form with no success..it let me submit the form with zero fields filled in even though I chose fields to be required...so Im back to square one when it comes to validation....:(

I will check back in the morning for any suggestions anyone may have...:)

edbr
05-04-2011, 08:26 AM
basically then its the variable names