Web Design Forum: Contact Form Post Issue - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Contact Form Post Issue not sure how to fix this one... Rate Topic: -----

#1 User is offline   nostrovia 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-May 09
  • Reputation: 0
  • Location:NYC
  • Experience:Nothing
  • Area of Expertise:Coder

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)">&lt;&lt; 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>");
}
}



?>
0

#2 User is offline   styledwebdesign 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 456
  • Joined: 04-June 08
  • Reputation: 0
  • Location:Cambridge, UK
  • Experience:Intermediate
  • Area of Expertise:Web Designer

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.
0

#3 User is offline   nostrovia 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-May 09
  • Reputation: 0
  • Location:NYC
  • Experience:Nothing
  • Area of Expertise:Coder

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?
0

#4 User is offline   Wickham 

  • Web Guru
  • View gallery
  • Group: Moderators
  • Posts: 2,682
  • Joined: 11-June 09
  • Reputation: 233
  • Gender:Male
  • Location:Salisbury UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

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.
0

#5 User is offline   nostrovia 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-May 09
  • Reputation: 0
  • Location:NYC
  • Experience:Nothing
  • Area of Expertise:Coder

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)">&lt;&lt; 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>");
}
0

#6 User is offline   Wickham 

  • Web Guru
  • View gallery
  • Group: Moderators
  • Posts: 2,682
  • Joined: 11-June 09
  • Reputation: 233
  • Gender:Male
  • Location:Salisbury UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

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'];
0

#7 User is offline   nostrovia 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-May 09
  • Reputation: 0
  • Location:NYC
  • Experience:Nothing
  • Area of Expertise:Coder

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)">&lt;&lt; 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>
0

#8 User is offline   dt17 

  • Advanced Member
  • PipPipPip
  • View gallery
  • Group: Members
  • Posts: 450
  • Joined: 22-May 09
  • Reputation: 14
  • Gender:Male
  • Location:Scotland
  • Experience:Advanced
  • Area of Expertise:Web Developer

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!
0

#9 User is offline   nostrovia 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-May 09
  • Reputation: 0
  • Location:NYC
  • Experience:Nothing
  • Area of Expertise:Coder

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!
0

#10 User is offline   dt17 

  • Advanced Member
  • PipPipPip
  • View gallery
  • Group: Members
  • Posts: 450
  • Joined: 22-May 09
  • Reputation: 14
  • Gender:Male
  • Location:Scotland
  • Experience:Advanced
  • Area of Expertise:Web Developer

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
$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)">&lt;&lt; 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!
0

#11 User is offline   nostrovia 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 16-May 09
  • Reputation: 0
  • Location:NYC
  • Experience:Nothing
  • Area of Expertise:Coder

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.
0

#12 User is offline   dt17 

  • Advanced Member
  • PipPipPip
  • View gallery
  • Group: Members
  • Posts: 450
  • Joined: 22-May 09
  • Reputation: 14
  • Gender:Male
  • Location:Scotland
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 21 June 2009 - 02:32 PM

Glad I can help, feel free to message me anytime :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users