It sends some of the info but not all. here is the code below.
HTML Code:
<div id="contact-wrapper">
<?php if(isset($hasError)) { //If errors are found ?> <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p> <?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p><strong>Email Successfully Sent!</strong></p> <p>Thank you <strong><?php echo $name;?></strong> for using my contact form! Your email was successfully sent and I will be in touch with you soon.</p> <?php } ?>
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the companyname field is not empty
if(trim($_POST['companyname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['companyname']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['telephone']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['telephone']);
}
//Check to make sure that the whentocall field is not empty
if(trim($_POST['whentocall']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['whentocall']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['whichplan']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['whichplan']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['whichphone']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['whichphone']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['whatbusiness']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['whatbusiness']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['employees']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['employees']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['lines']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['lines']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['extensions']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['extensions']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['comments']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['comments']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure that the name field is not empty
if(trim($_POST['referralcontactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['referralcontactname']);
}
//Check to make sure that the companyname field is not empty
if(trim($_POST['referralcompanyname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['referralcompanyname']);
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['referraltelephone']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['referraltelephone']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['referralemail']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['referralemail']))) {
$hasError = true;
} else {
$email = trim($_POST['referralemail']);
}
//Check to make sure comments were entered
if(trim($_POST['comments']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'ryanshawgd@gmail.com, mdunbavan@gmail.com'; //Put your own email address here
$body = "\n\nFull name: \n$contactname
\n\nEmail: \n$email
\n\nTelephone: \n$telephone
\n\nComments:\n $comments
\n\nCompany Name:\n $companyname
\n\nWhich Plan:\n $whichplan
\n\nWhich Phone:\n $whichphone
\n\nWhen should we call you?:\n $whentocall
\n\nType of business:\n $whatbusiness
\n\nNumber of employees:\n $employees
\n\nExisting number of lines:\n $lines
\n\nExisting number of extensions:\n $extensions
\n\nReferrer contact name:\n $referralcontactname
\n\nReferral email:\n $referralemail
\n\nReferral telephone:\n $referraltelephone
\n\nReferral company name:\n $referralcompanyname";
$headers = 'From: Digivox Referrals/Tester email <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
okay so I made the changes but it still does exactly the same thing. This is what I entered in to php:
PHP Code:
//Check to make sure that the name field is not empty if(urldecode(trim($_POST['contactname'])) == '') { $hasError = true; } else { $name = trim($_POST['contactname']); }
Does this also need to be included on the bottom part of the code here where we have:
PHP Code:
$name = trim($_POST['contactname']);
Thanks,
Mark:)
09-13-2010, 04:27 PM
Chipzzz
By all means, you should urldecode() all of the $_POST assignments. Also, I notice that all of your $_POST[] elements are assigned to either $name, $subject, $email, or $comments. If you look down further in the '//If there is no error, send the email' section, you will see additional variables to which some of them might be more appropriately assigned.
Good luck and have a nice day :)
09-13-2010, 04:53 PM
markdunbavan
Yes well I am kind of new to php but this is what I changed from the original first line so far;
I saw a few things that were not quite right but I am hoping this will help it a long a bit. The only problem I have is when I click to submit it usually sends the form without some of the information. now it says there is an error.
This seems to be a good thing because it must mean the php code was wrong and now must be slowly getting to what it should be.
09-13-2010, 05:38 PM
Chipzzz
$_POST['\n$contactname'] should be $_POST['$contactname'] (the variable begins with '$').
It's getting there, though :)
09-13-2010, 05:47 PM
markdunbavan
Thanks a lot. I am still struggling with it. All i get back on the form is:
"Please check if you've filled all the fields with valid information. Thank you."
I know that this is what I wrote in the php code but cannot see where it is that could be happening because I filled all the form fields out.
Arghhhhhhhhhh!:(
Sorry of I am starting to annoy you but I wanna get this nailed!
09-13-2010, 09:39 PM
Chipzzz
Part 1
Lol... although I'll admit it was an aggravating day, your project had little to do with it and by a happy coincidence, I've learned that when I feel cranky it always makes me happier to do something nice for someone... The code below needs a little work, but they are only cosmetic and minor things that you'll find instructive to tinker with. Although it's a single file, I have to send it in two parts due to its size... the php section (this part) goes first and the html second (next message).
Code:
<?php
//If the form is submitted
if (!isset($_POST['submit'])) {
// Prevent undefined variables in the html section
$vars = array('errmsg', 'contactname', 'companyname', 'email', 'telephone',
'whentocall', 'whichplan', 'whichphone', 'whatbusiness', 'employees',
'lines', 'extensions', 'comments', 'referralcontactname', 'referralcompanyname',
'referralemail', 'referraltelephone');
foreach($vars as $v) {
$$v = '';
}
} else {
foreach ($_POST as $key => $val) {
$$key = urldecode(trim($val));
}
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
$errmsg = 'Contact name is empty';
}
//Check to make sure that the companyname field is not empty
if(trim($_POST['companyname']) == '') {
$hasError = true;
$errmsg = 'Company name is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['telephone']) == '') {
$hasError = true;
$errmsg = 'Telephone is empty';
}
//Check to make sure that the whentocall field is not empty
if(trim($_POST['whentocall']) == '') {
$hasError = true;
$errmsg = 'When to call is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['whichplan']) == '') {
$hasError = true;
$errmsg = 'Which plan is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['whichphone']) == '') {
$hasError = true;
$errmsg = 'Telephone is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['whatbusiness']) == '') {
$hasError = true;
$errmsg = 'Business is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['employees']) == '') {
$hasError = true;
$errmsg = 'employees is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['lines']) == '') {
$hasError = true;
$errmsg = 'Lines is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['extensions']) == '') {
$hasError = true;
$errmsg = 'Extensions is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['comments']) == '') {
$hasError = true;
$errmsg = 'Comments is empty';
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
$errmsg = 'Email is empty';
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
$errmsg = 'Email is invalid';
}
//Check to make sure that the name field is not empty
if(trim($_POST['referralcontactname']) == '') {
$hasError = true;
$errmsg = 'Referral name is empty';
}
//Check to make sure that the companyname field is not empty
if(trim($_POST['referralcompanyname']) == '') {
$hasError = true;
$errmsg = 'Referral company is empty';
}
//Check to make sure that the telephone field is not empty
if(trim($_POST['referraltelephone']) == '') {
$hasError = true;
$errmsg = 'Referral teltphone is empty';
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['referralemail']) == '') {
$hasError = true;
$errmsg = 'Referral email is empty';
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['referralemail']))) {
$hasError = true;
$errmsg = 'Referral email is invalid';
}
//Check to make sure comments were entered
if(trim($_POST['comments']) == '') {
$hasError = true;
$errmsg = 'Comments is empty';
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'ryanshawgd@gmail.com, mdunbavan@gmail.com'; //Put your own email address here
$body = "\n\nFull name: \n$contactname
\n\nEmail: \n$email
\n\nTelephone: \n$telephone
\n\nComments:\n $comments
\n\nCompany Name:\n $companyname
\n\nWhich Plan:\n $whichplan
\n\nWhich Phone:\n $whichphone
\n\nWhen should we call you?:\n $whentocall
\n\nType of business:\n $whatbusiness
\n\nNumber of employees:\n $employees
\n\nExisting number of lines:\n $lines
\n\nExisting number of extensions:\n $extensions
\n\nReferrer contact name:\n $referralcontactname
\n\nReferral email:\n $referralemail
\n\nReferral telephone:\n $referraltelephone
\n\nReferral company name:\n $referralcompanyname";
$headers = 'From: Digivox Referrals/Tester email <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head></head>
<body>
<div id="contact-wrapper">
<?php if(isset($hasError)) { //If errors are found ?>
<p class="error">Please check for the following error: <?php echo $errmsg ?>. Thank you.</p>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<p><strong>Email Successfully Sent!</strong></p>
<p>Thank you <strong><?php echo $name;?></strong> for using my contact form! Your email was successfully sent and I will be in touch with you soon.</p>
<?php } ?>
Thats quite funny but brilliant in another way. Thank you for your help. So let me get this straight. The code we have here has missing parts on purpose so I have to find them. I tried sending the form and it displayed the have you filled in everything text so i am assuming I need to go into the php and find the parts missing and fill them in?
Thanks so much
Mark:o
09-14-2010, 04:07 PM
Chipzzz
Hi Mark,
Well, I figured if you wanted it all done for you, you'd have gone to Rent-A-Coder or someplace like that, so coupled with my intrinsic laziness, I thought I would fix it enough that you would be able to learn from what I had done as well as fix a few odds and ends on your own. For example, I'm sure you don't want comments to be mandatory, yet as originally written, they were. I'm sure you can fix it, so I left it that way. Similarly, but a little more difficult, you might like the form displayed in a table so that you had columns of labels and columns of data. You'll have to stretch your abilities a bit but I think you'll be able to manage it, so I left that for you. That's all that comes immediately to mind in that regard, and as for learning from the code as it stands, I would draw your attention to the beginning of the file, where the $_POST array is read. I think you'll appreciate the efficiency with which that is done as opposed to the original version. Also, the 'have you filled in everything' has been enhanced to include a more specific error message. So, in summary, the code is fully functional but as I said, it could stand a few cosmetic improvements and some tinkering of which I think you are probably capable. If I misread the situation, I apologize and will continue improving it as time permits.
Thanks for the praise (a pat on the back is always welcome) & have a nice evening :)
09-16-2010, 04:17 PM
markdunbavan
Hi Chipzz.
Just a quick update. Been tinkering with the php form and added a few things and now just trying to figure out how to get some of the input area's to sit next to each other horizontally. This will make it loads more compact and easier to fill in as opposed to it being really long and arduous.
I have seen a few of the things you did and they are great. Thanks again.
I will post up here the finished site so you can see what I have been doing.
Thanks,
Mark
09-16-2010, 09:00 PM
Chipzzz
Good work and I look forward to seeing it. There are a couple of ways to do what you want. The quickest and easiest is probably to embed a table in the form as explained here: http://www.w3schools.com/html/html_tables.asp .