Page 1 of 1
Contact Form Post Issue not sure how to fix this one...
#1
Posted 20 June 2009 - 03:04 PM
http://www.changemyw...php?p=contactus
hey all. this is my html contact form and my contactus_process php script, but im not sure how to get it to actually work with the form. thoughts?
thanks in advance everyone.
<form class="contactform" method="post">
<label style="color:#FFFFFF;font-size:15px;">Name:</label><input class="formfield"/>
<label style="color:#FFFFFF;font-size:15px;">Email:</label><input class="formfield"/>
<label style="color:#FFFFFF;font-size:15px;">Subject:</label><input class="formfield"/>
<label style="color:#FFFFFF;font-size:15px;">Comment:</label><textarea class="commentsbox"></textarea><br /><br />
<input style="border:none;width:75px;margin-top:10px;font-size:14px;" type="submit" value="Submit" />
</form>
</body>
</html>
<?php
$nameraw = $_POST['Name'];
$emailraw = $_POST['EMail'];
$subjectraw = $_POST['Subject'];
$commentraw = $_POST['Comment'];
?>
<?php
$namecount = strlen($nameraw);
if ($namecount >=2){$name=$nameraw;}else{$error1="Name must consist of more than one character";}
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailraw)){$email=$emailraw;}else{$error3="Email Address must consist of a . and a @";}
$commentcount = strlen($commentraw);
if ($commentcount >=3){$comment=$commentraw;}else{error4="Comment must consist of more than 3 characters";}
if (isset($error1)||isset($error2)||isset($error3)||isset($error4)||
<?php if (isset($error1)){echo"$error1<br />";}?>
<?php if (isset($error2)){echo"$error2<br />";}?>
<?php if (isset($error3)){echo"$error3<br />";}?>
<?php if (isset($error4)){echo"$error4<br />";}?>
<a href="java script:java script:history.go(-1)"><< GO BACK</a>
<?php
}else{ //send the email
$to = "mike.koffler@gmail.com";
$subject = "Contact Form Submission";
$body = "
Mike,
Someone has submitted the following information on your web site contact form:
$name
Subject:
$subject
Comment:
$comment
Email: $email
Best,
Your Webmaster
";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent</p>");
} else {
echo("<p>Message delivery failed</p>");
}
}
?>
hey all. this is my html contact form and my contactus_process php script, but im not sure how to get it to actually work with the form. thoughts?
thanks in advance everyone.
<form class="contactform" method="post">
<label style="color:#FFFFFF;font-size:15px;">Name:</label><input class="formfield"/>
<label style="color:#FFFFFF;font-size:15px;">Email:</label><input class="formfield"/>
<label style="color:#FFFFFF;font-size:15px;">Subject:</label><input class="formfield"/>
<label style="color:#FFFFFF;font-size:15px;">Comment:</label><textarea class="commentsbox"></textarea><br /><br />
<input style="border:none;width:75px;margin-top:10px;font-size:14px;" type="submit" value="Submit" />
</form>
</body>
</html>
<?php
$nameraw = $_POST['Name'];
$emailraw = $_POST['EMail'];
$subjectraw = $_POST['Subject'];
$commentraw = $_POST['Comment'];
?>
<?php
$namecount = strlen($nameraw);
if ($namecount >=2){$name=$nameraw;}else{$error1="Name must consist of more than one character";}
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailraw)){$email=$emailraw;}else{$error3="Email Address must consist of a . and a @";}
$commentcount = strlen($commentraw);
if ($commentcount >=3){$comment=$commentraw;}else{error4="Comment must consist of more than 3 characters";}
if (isset($error1)||isset($error2)||isset($error3)||isset($error4)||
<?php if (isset($error1)){echo"$error1<br />";}?>
<?php if (isset($error2)){echo"$error2<br />";}?>
<?php if (isset($error3)){echo"$error3<br />";}?>
<?php if (isset($error4)){echo"$error4<br />";}?>
<a href="java script:java script:history.go(-1)"><< GO BACK</a>
<?php
}else{ //send the email
$to = "mike.koffler@gmail.com";
$subject = "Contact Form Submission";
$body = "
Mike,
Someone has submitted the following information on your web site contact form:
$name
Subject:
$subject
Comment:
$comment
Email: $email
Best,
Your Webmaster
";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent</p>");
} else {
echo("<p>Message delivery failed</p>");
}
}
?>
#2
Posted 20 June 2009 - 03:17 PM
You need;
<form class="contactform" method="post" action="form.php">
then save your php as form.php in the same directory.
<form class="contactform" method="post" action="form.php">
then save your php as form.php in the same directory.
#3
Posted 20 June 2009 - 03:29 PM
Parse error: syntax error, unexpected '=' in /home/changemy/public_html/form.php on line 18
Line 18 - if ($commentcount >=3){$comment=$commentraw;}else{error4="Comment must consist of more than 3 characters";}
where is the unexpected "="?
i changed the php file to form.php on the server.
i can't seem to get it to link up, thoughts?
Line 18 - if ($commentcount >=3){$comment=$commentraw;}else{error4="Comment must consist of more than 3 characters";}
where is the unexpected "="?
i changed the php file to form.php on the server.
i can't seem to get it to link up, thoughts?
#4
Posted 20 June 2009 - 05:22 PM
There's only one = in that line. I think it should be either
if ($commentcount >3){$comment=$commentraw;}else{error4="Comment must consist of more than 3 characters";}
if you want to check if more than 3 characters or ($commentcount <3) less than 3 or ($commentcount ==3) for equal to 3.
if ($commentcount >3){$comment=$commentraw;}else{error4="Comment must consist of more than 3 characters";}
if you want to check if more than 3 characters or ($commentcount <3) less than 3 or ($commentcount ==3) for equal to 3.
#5
Posted 20 June 2009 - 07:16 PM
the problem was I forgot to put a $ before error4.
but im still having some problems with the form. its still saying theres an issue in line 56, which is the final line. any ideas?
<?php
$nameraw = $_POST['Name'];
$emailraw = $_POST['EMail'];
$titleraw = $_POST['Title'];
$commentraw = $_POST['Comment'];
?>
<?php
$namecount = strlen($nameraw);
if ($namecount >=2){$name=$nameraw;}else{$error1="Name must consist of more than one character";}
$titlecount = strlen($titleraw);
if ($titlecount >=2){$title=$titleraw;}else{$error2="Title must consist of more than one character";}
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailraw)){$email=$emailraw;}else{$error3="Email Address must consist of a . and a @";}
$commentcount = strlen($commentraw);
if ($commentcount >=3){$comment=$commentraw;}else{$error4="Comment must consist of more than 3 characters";}
if (isset($error1)||isset($error2)||isset($error3)||isset($error4)){?>
<?php if (isset($error1)){echo"$error1<br />";}?>
<?php if (isset($error2)){echo"$error2<br />";}?>
<?php if (isset($error3)){echo"$error3<br />";}?>
<?php if (isset($error4)){echo"$error4<br />";}?>
<a href="java script:java script:history.go(-1)"><< GO BACK</a>
<?php
}else{ //send the email
$to = "mike.koffler@gmail.com";
$subject = "Contact Form Submission";
$body = "
Mike,
Someone has submitted the following information on your web site contact form:
$name
Title:
$title
Comment:
$comment
Email: $email
Best,
Your Webmaster
";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent</p>");
} else {
echo("<p>Message delivery failed</p>");
}
but im still having some problems with the form. its still saying theres an issue in line 56, which is the final line. any ideas?
<?php
$nameraw = $_POST['Name'];
$emailraw = $_POST['EMail'];
$titleraw = $_POST['Title'];
$commentraw = $_POST['Comment'];
?>
<?php
$namecount = strlen($nameraw);
if ($namecount >=2){$name=$nameraw;}else{$error1="Name must consist of more than one character";}
$titlecount = strlen($titleraw);
if ($titlecount >=2){$title=$titleraw;}else{$error2="Title must consist of more than one character";}
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailraw)){$email=$emailraw;}else{$error3="Email Address must consist of a . and a @";}
$commentcount = strlen($commentraw);
if ($commentcount >=3){$comment=$commentraw;}else{$error4="Comment must consist of more than 3 characters";}
if (isset($error1)||isset($error2)||isset($error3)||isset($error4)){?>
<?php if (isset($error1)){echo"$error1<br />";}?>
<?php if (isset($error2)){echo"$error2<br />";}?>
<?php if (isset($error3)){echo"$error3<br />";}?>
<?php if (isset($error4)){echo"$error4<br />";}?>
<a href="java script:java script:history.go(-1)"><< GO BACK</a>
<?php
}else{ //send the email
$to = "mike.koffler@gmail.com";
$subject = "Contact Form Submission";
$body = "
Mike,
Someone has submitted the following information on your web site contact form:
$name
Title:
$title
Comment:
$comment
Email: $email
Best,
Your Webmaster
";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent</p>");
} else {
echo("<p>Message delivery failed</p>");
}
#6
Posted 20 June 2009 - 08:09 PM
Your first post had the PHP ending
echo("<p>Message delivery failed</p>");
}
}
?>
but your last post had
echo("<p>Message delivery failed</p>");
}
you need the extra } to end the { where you have { //send the email
and also the ?>
I'm also a bit concerned that your form input tags don't have a name="..." like
<input name="EMail" class="formfield"/> for the PHP variable to find with $_POST['EMail'];
echo("<p>Message delivery failed</p>");
}
}
?>
but your last post had
echo("<p>Message delivery failed</p>");
}
you need the extra } to end the { where you have { //send the email
and also the ?>
I'm also a bit concerned that your form input tags don't have a name="..." like
<input name="EMail" class="formfield"/> for the PHP variable to find with $_POST['EMail'];
#7
Posted 20 June 2009 - 10:04 PM
Wickham, I appreciate all the help.
Here's where I stand now. I feel like I'm so close. It's saying now there's a problem on line 27, that there's a problem with the "}else{" next to the commented out //send the email. What do you think?
<?php
$nameraw = $_POST['Name'];
$titleraw = $_POST['Title'];
$emailraw = $_POST['Email'];
$commentsraw = $_POST['Comments'];
?>
<?php
$namecount = strlen($nameraw);
if ($namecount >=2){$name=$nameraw;}else{$error1="Name must consist of more than one character";}
$titlecount = strlen($titlenameraw);
if ($titlecount >=2){$title=$titleraw;}else{$error2="Title must consist of more than one character";}
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailraw)){$email=$emailraw;}else{$error3="Email must consist of a . and a @";}
$commentscount = strlen($commentsraw);
if ($commentscount >=3){$comments=$commentsraw;}else{$error4="Comments must consist of more than 3 characters";}
if (isset($error1)||isset($error2)||isset($error3)||isset($error4))?>
<?php if (isset($error1)){echo"$error1<br />";}?>
<?php if (isset($error2)){echo"$error2<br />";}?>
<?php if (isset($error3)){echo"$error3<br />";}?>
<?php if (isset($error4)){echo"$error4<br />";}?>
<a href="java script:java script:history.go(-1)"><< GO BACK</a>
<?php
}else{ //send the email
$to = "mike.koffler@gmail.com";
$subject = "Contact Form Submission";
$body = "
Mike,
Someone has submitted the following information on your web site contact form:
$name
Comment:
$comments
Email: $email
Best,
Your Webmaster
";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent</p>");
} else {
echo("<p>Message delivery failed</p>");
}
}
?>
<form class="contactform" method="post" action="contact_process.php">
<label style="color:#FFFFFF;font-size:15px;">Name:</label><input class="formfield" type="text" id="Name"/>
<label style="color:#FFFFFF;font-size:15px;">Email:</label><input class="formfield" type="text" id="EMail"/>
<label style="color:#FFFFFF;font-size:15px;">Title:</label><input class="formfield" type="text" id="Title"/>
<label style="color:#FFFFFF;font-size:15px;">Comments:</label><textarea class="commentsbox" type="text" id="Comments"></textarea><br /><br />
<input style="border:2px solid #18537F;width:100px;margin-top:10px;font-size:14px;" type="submit" value="Submit" />
</form>
Here's where I stand now. I feel like I'm so close. It's saying now there's a problem on line 27, that there's a problem with the "}else{" next to the commented out //send the email. What do you think?
<?php
$nameraw = $_POST['Name'];
$titleraw = $_POST['Title'];
$emailraw = $_POST['Email'];
$commentsraw = $_POST['Comments'];
?>
<?php
$namecount = strlen($nameraw);
if ($namecount >=2){$name=$nameraw;}else{$error1="Name must consist of more than one character";}
$titlecount = strlen($titlenameraw);
if ($titlecount >=2){$title=$titleraw;}else{$error2="Title must consist of more than one character";}
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailraw)){$email=$emailraw;}else{$error3="Email must consist of a . and a @";}
$commentscount = strlen($commentsraw);
if ($commentscount >=3){$comments=$commentsraw;}else{$error4="Comments must consist of more than 3 characters";}
if (isset($error1)||isset($error2)||isset($error3)||isset($error4))?>
<?php if (isset($error1)){echo"$error1<br />";}?>
<?php if (isset($error2)){echo"$error2<br />";}?>
<?php if (isset($error3)){echo"$error3<br />";}?>
<?php if (isset($error4)){echo"$error4<br />";}?>
<a href="java script:java script:history.go(-1)"><< GO BACK</a>
<?php
}else{ //send the email
$to = "mike.koffler@gmail.com";
$subject = "Contact Form Submission";
$body = "
Mike,
Someone has submitted the following information on your web site contact form:
$name
Comment:
$comments
Email: $email
Best,
Your Webmaster
";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent</p>");
} else {
echo("<p>Message delivery failed</p>");
}
}
?>
<form class="contactform" method="post" action="contact_process.php">
<label style="color:#FFFFFF;font-size:15px;">Name:</label><input class="formfield" type="text" id="Name"/>
<label style="color:#FFFFFF;font-size:15px;">Email:</label><input class="formfield" type="text" id="EMail"/>
<label style="color:#FFFFFF;font-size:15px;">Title:</label><input class="formfield" type="text" id="Title"/>
<label style="color:#FFFFFF;font-size:15px;">Comments:</label><textarea class="commentsbox" type="text" id="Comments"></textarea><br /><br />
<input style="border:2px solid #18537F;width:100px;margin-top:10px;font-size:14px;" type="submit" value="Submit" />
</form>
#8
Posted 20 June 2009 - 11:56 PM
I tried the code and didn't get any error message, however, I didn't get any success/failure messages either. I'll investigate!
#9
Posted 21 June 2009 - 01:11 AM
great thanks dt. ive been working on this for a while and im starting to rip my hair out!
#10
Posted 21 June 2009 - 09:51 AM
Alright, a couple problem's I have spotted with the code.
Firstly, your HTML form elements need a "name" attribute in order to use the associative POST array to retrieve the details.
Secondly, your title count was wrong, you had
Thirdly, you try to use your if else statement on this line
This is what the code looks like now after fixing those problems:
contact_process.php
index.html
NOTE: I removed all the styling etc. from the buttons and forms as I didn't have the stylesheet and I couldn't see anything.
Hope this helped!
Firstly, your HTML form elements need a "name" attribute in order to use the associative POST array to retrieve the details.
Secondly, your title count was wrong, you had
$titlecount = strlen($titlenameraw);when it should be
$titlecount = strlen($titleraw);
Thirdly, you try to use your if else statement on this line
if (isset($error1)||isset($error2)||isset($error3)||isset($error4))?>.. however, you did not open the if statements actions with a curly brace. The code should read like
if (isset($error1)||isset($error2)||isset($error3)||isset($error4)){?>This is what the code looks like now after fixing those problems:
contact_process.php
<?php
$nameraw = $_POST['Name'];
$titleraw = $_POST['Title'];
$emailraw = $_POST['EMail'];
$commentsraw = $_POST['Comments'];
/*
echo $nameraw;
echo $titleraw;
echo $emailraw;
echo $commentsraw;*/
?>
<?php
$namecount = strlen($nameraw);
if ($namecount >=2){$name=$nameraw;}else{$error1="Name must consist of more than one character";}
$titlecount = strlen($titleraw);
echo $titlecount;
if ($titlecount >=2){$title=$titleraw;}else{$error2="Title must consist of more than one character";}
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailraw)){$email=$emailraw;}else{$error3="Email must consist of a . and a @";}
$commentscount = strlen($commentsraw);
if ($commentscount >=3){$comments=$commentsraw;}else{$error4="Comments must consist of more than 3 characters";}
if (isset($error1)||isset($error2)||isset($error3)||isset($error4)){?>
<?php if (isset($error1)){echo"$error1<br />";}?>
<?php if (isset($error2)){echo"$error2<br />";}?>
<?php if (isset($error3)){echo"$error3<br />";}?>
<?php if (isset($error4)){echo"$error4<br />";}?>
<a href="java script:java script:history.go(-1)"><< GO BACK</a>
<?php
}else{ //send the email
$to = "mike.koffler@gmail.com";
$subject = "Contact Form Submission";
$body = "
Mike,
Someone has submitted the following information on your web site contact form:
$name
Comment:
$comments
Email: $email
Best,
Your Webmaster
";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent</p>");
} else {
echo("<p>Message delivery failed</p>");
}
}
?>index.html
<form id="contact" method="POST" action="contact_process.php"> <label>Name:</label><input type="text" id="Name" name="Name"/> <label>Email:</label><input type="text" id="EMail" name="EMail"/> <label>Title:</label><input type="text" id="Title" name="Title"/> <label>Comments:</label><textarea type="text" id="Comments" name="Comments"></textarea><br /><br /> <input type="submit" value="Submit" /> </form>
NOTE: I removed all the styling etc. from the buttons and forms as I didn't have the stylesheet and I couldn't see anything.
Hope this helped!
#11
Posted 21 June 2009 - 01:27 PM
Success!
Thanks a lot dt.
I hope you don't mind if I PM you with any more questions I might have. You've been a huge help.
Thanks a lot dt.
I hope you don't mind if I PM you with any more questions I might have. You've been a huge help.
- ← Learning PHP
- Server Side (PHP, Databases, ASP.NET, etc)
- Making the most recent comment visible in a different location. →
Share this topic:
Page 1 of 1
Help


















