Contact Form 
July 17th, 2005, 04:17 AM
| | | Contact Form
I'm struggling with this email code and I'm not php freak since I'm
starting to learn php stuff. Could use some help...
It seems that I get too many parse errors all over and cannot figure
went wrong since most of these appears right to me...
<?PHP
$to = "scoobyood@jace41.com" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;
//validate contact fields
if (!strstr(trim($_POST['email']),"@"))
{
$email_error = "<p class='comment'>please enter your email
address!</p><br>";
$contact = "no";
}
if ($_POST['name'] == "")
{
$name_error = "<p class='comment'>name field is blank!</p><br>";
$contact = "no";
}
if ($_POST['email'] == "")
{
$email_error = "<p class='comment'>email field is blank!</p><br>";
$contact = "no";
}
if ($_POST['subject'] == "")
{
$subject_error = "<p class='comment'>subject field is
blank!</p><br>";
$contact = "no";
}
if ($_POST['message'] == "")
{
$message_error = "<p class='comment'>message field is
blank</p><br>";
$contact = "no";
}
if ($contact != "no")
{
//if pass, then submit email and redirect to thankyou page
mail($to, $subject, $message, "From: $name <$email>");
{
header("Location: contactsent.html");
exit();
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<link href="css/jace2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p class="topic">Unable to send your message!</p><br>
<?PHP
//list error(s)
else if $send == "no");
{
echo "$name_error";
echo "$email_error";
echo "$subject_error";
echo "$message_error";
}
?>
<p> Click your browser's "back" button to return to the
contact form and fill missing fields.<br>
</p>
</body>
</html> | 
July 17th, 2005, 04:18 AM
| | | Re: Contact Form
Jason wrote:[color=blue]
> It seems that I get too many parse errors all over and cannot figure
> went wrong since most of these appears right to me...
>
> <?PHP[/color]
(snip)[color=blue]
> if ($contact != "no")
> {[/color]
You never closed this '{' for the if
[color=blue]
> //if pass, then submit email and redirect to thankyou page
> mail($to, $subject, $message, "From: $name <$email>");
> {
> header("Location: contactsent.html");
> exit();
> }
>
>
> ?>[/color]
(snip HTML)[color=blue]
><?PHP
>
> //list error(s)
> else if $send == "no");[/color]
This if does not have an '('
Are you sure you want the if to do nothing?
if ($send == "no");
is a complete instruction. The next '{' is *not* part of the if().
[color=blue]
> {[/color]
(snip more code)
HTH
--
USENET would be a better place if everybody read: : mail address : http://www.catb.org/~esr/faqs/smart-questions.html : is valid for : http://www.netmeister.org/news/learn2quote2.html : "text/plain" : http://www.expita.com/nomime.html : to 10K bytes : | 
July 17th, 2005, 04:18 AM
| | | Re: Contact Form
Pedro, thanks for help! I just redefined the script to make it more
sense and still get parse errors (seem "else" statement is main parse
error problem):
<?PHP
$to = "scoobyood@jace41.com" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<link href="css/jace2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p class="topic">Unable to send your message!</p><br>
<?PHP
//Validate all fields
if (!strstr(trim($_POST['email']),"@"))
{
$email_error = "<p class='comment'>please enter your email
address!</p><br>";
$contact = "no";
}
if ($_POST['name'] == "")
{
$name_error = "<p class='comment'>name field is blank!</p><br>";
$contact = "no";
}
if ($_POST['email'] == "")
{
$email_error = "<p class='comment'>email field is blank!</p><br>";
$contact = "no";
}
if ($_POST['subject'] == "")
{
$subject_error = "<p class='comment'>subject field is
blank!</p><br>";
$contact = "no";
}
if ($_POST['message'] == "")
{
$message_error = "<p class='comment'>message field is
blank</p><br>";
$contact = "no";
}
//if form fail, echo error lists and exit script
if ($contact != "no")
{
echo "$name_error";
echo "$email_error";
echo "$subject_error";
echo "$message_error";
{
exit();
}
//if form pass, submit email and redirect to thank you page
else {
mail($to, $subject, $message, "From: $name <$email>");
{
header("Location: contactsent.html");
exit();
}
?>
<p> Click your browser's "back" button to return to the
contact form and fill missing fields.<br>
</p>
</body>
</html> | 
July 17th, 2005, 04:18 AM
| | | Re: Contact Form
Jason wrote:[color=blue]
>
> Pedro, thanks for help! I just redefined the script to make it more
> sense and still get parse errors (seem "else" statement is main parse
> error problem):[/color]
[color=blue]
> //if form fail, echo error lists and exit script
> if ($contact != "no")
> {
> echo "$name_error";
> echo "$email_error";
> echo "$subject_error";
> echo "$message_error";
> {
> exit();
> }[/color]
Take a look at the brackets. How opening, how many closing? How many
should there be.
[color=blue]
> //if form pass, submit email and redirect to thank you page
> else {
> mail($to, $subject, $message, "From: $name <$email>");
> {
> header("Location: contactsent.html");
> exit();
> }[/color]
Once again, look at the brackets.
This is not difficult stuff. You are obviously not going over your code
carefully. Use a consistent indentation style and examine your code when
parse problems occur. Don't worry about the number of them, a misplaced
bracket or paren will often cause multiple errors.
Brian Rodenborn | 
July 17th, 2005, 04:18 AM
| | | Re: Contact Form
I noticed that Message-ID:
<ed5ca32c.0403191017.1ef2714e@posting.google.com > from Jason contained
the following:
[color=blue]
>else {
> mail($to, $subject, $message, "From: $name <$email>");
> {
> header("Location: contactsent.html");
> exit();
> }[/color]
Missing }
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ | 
July 17th, 2005, 04:19 AM
| | | Re: Contact Form
try using a program that number the lines so you can see the number of each
line (PHPEdit for example) When php shows an error message it will tell you
on what line the error occured it is ussually the case that it is right or
that it is a line before (in such cases where a ; is missing) | 
July 17th, 2005, 04:20 AM
| | | Re: Contact Form
Really appreciate help and sure leanred php alot in one week! I
managed to get contact form to work but still having some trouble with
eregi (validate email addy with "@") and header to redirect to
thankyou page. I tried full header addy and various tricks but no
avail and suspect it's due to "echo" above the header script. As for
eregi, it failed to validate email with "@". Any idea??
<?PHP
$to = "scoobyood@jace41.com" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;
$undelivery = "";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<link href="css/jace2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?PHP
// validate the email with "@"
if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$',
$email))
$undelivery ."<span class=\"comment\">email's invalid!</span><br>";
// validate the email
if (!$_POST['email'])
$undelivery .= "<span class=\"comment\">email field's
empty!</span><br>";
// validate the name
if (!$_POST['name'])
$undelivery .= "<span class=\"comment\">name field's
empty!</span><br>";
// validate the subject
if (!$_POST['subject'])
$undelivery .= "<span class=\"comment\">subject field's
empty!</span><br>";
// validate the message
if (!$_POST['message'])
$undelivery .= "<span class=\"comment\">message field's
empty!</span><br>";
// display error lists
if ($undelivery)
echo $undelivery;
else {
// if pass, then email form and redirect to thank you page
mail($to, $subject, $message,"From: $name <$email>");
header("Location: contactsent.html");
}
?>
</body>
</html>
.. | 
July 17th, 2005, 04:20 AM
| | | Re: Contact Form
> As for[color=blue]
> eregi, it failed to validate email with "@". Any idea??[/color]
I validate emails using the folowing, there is a couple of missing
characters however as + can also be used in the first part of an email
address
!eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",
$_POST['email']) | 
July 17th, 2005, 04:20 AM
| | | Re: Contact Form
On 2004-03-22, Filth <p.macdonald@blueyonder.co.uk> wrote:[color=blue][color=green]
>> As for
>> eregi, it failed to validate email with "@". Any idea??[/color]
>
> I validate emails using the folowing, there is a couple of missing
> characters however as + can also be used in the first part of an email
> address
>
> !eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",
> $_POST['email'])[/color]
Do a google search for "rfc822 regular expression".
And at phpclasses.org there is a mail validation class too.
-- http://home.mysth.be/~timvw | 
July 17th, 2005, 04:20 AM
| | | Re: Contact Form
"Filth" <p.macdonald@blueyonder.co.uk> wrote in message news:<QMz7c.830$uM6.505@news-binary.blueyonder.co.uk>...[color=blue][color=green]
> > As for
> > eregi, it failed to validate email with "@". Any idea??[/color]
>
> I validate emails using the folowing, there is a couple of missing
> characters however as + can also be used in the first part of an email
> address
>
> !eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",
> $_POST['email'])[/color]
I tried your ereg and it still doesn't working. I also tried another
ereg scripts I came across in internet and all seem won't work too. I
might miss something. As for phpclasses.org, I'll look into it later
when I have time...Thanks for help and tips!
Jace | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|