Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact Form Post Issue

Featured Replies

http://www.changemyworkout.com/index2.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>");

}

}

 

 

 

?>

You need;

 

<form class="contactform" method="post" action="form.php">

 

then save your php as form.php in the same directory.

  • Author

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?

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.

  • Author

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>");

}

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

  • Author

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>

I tried the code and didn't get any error message, however, I didn't get any success/failure messages either. I'll investigate!

  • Author

great thanks dt. ive been working on this for a while and im starting to rip my hair out!

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)"><< 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!

  • Author

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.

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

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.