.PHP form submit not working - php

I would like people to be able to submit their contact info via a form I have on the site. I have no clue how to code PHP myself, so I snagged a "working model" and made some edits to fit my site. Here is the HTML code:
<form name="contact" method="post" action="formsubmit.php">
<li>
<input name="first_name" type="text" value="first name (Required)" onfocus="if(this.value == 'first name') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'first name'; }" />
<input name="last_name" type="text" value="last name (Required)" onfocus="if(this.value == 'last name') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'last name'; }" />
<input name="email" type="text" value="email (Required)" onfocus="if(this.value == 'email (Required)') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'email (Required)'; }" />
<input name="telephone" type="text" value="phone" onfocus="if(this.value == 'phone (Required)') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'phone'; }" />
<input name="comments" type="text" value="What are your goals?" onfocus="if(this.value == 'What are your goals?') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'What are your goals?'; }" />
<div class="g-recaptcha" data-sitekey="I am using site key here, just wasn't sure if the public should be privy to that info or not"></div>
</li>
</form>
<li>
<input type="submit" value="SUBMIT" class="submitbtn" form="contact" />
</li>
And here is the .php
<!doctype html>
<html>
<head>
<!-- CSS -->
<link href="main.css" rel="stylesheet" type="text/css" />
<meta charset="UTF-8">
<title>We Will EnduroFit</title>
</head>
<body>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "someone#example.com";
$email_subject = "Message from website visitor";
function died($error) {
// your error code can go here
echo "I am sorry, but there were error(s) found with the form you submitted.";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('I am sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include success html here -->
<h2>Thanks! I will respond to you soon :)</h2>
<?php
}
?>
</body>
</html>
If anyone can take a look at that and tell me what I am missing. The submit button just acts like its dead. It does nothing at all. I know it was working as a model, so I have no idea what I did/did not change to break the stupid submit button. Thanks a million!

Try this: I've change the location of your closing form tag
<form name="contact" method="post" action="formsubmit.php">
<li>
<input name="first_name" type="text" value="first name (Required)" onfocus="if(this.value == 'first name') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'first name'; }" />
<input name="last_name" type="text" value="last name (Required)" onfocus="if(this.value == 'last name') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'last name'; }" />
<input name="email" type="text" value="email (Required)" onfocus="if(this.value == 'email (Required)') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'email (Required)'; }" />
<input name="telephone" type="text" value="phone" onfocus="if(this.value == 'phone (Required)') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'phone'; }" />
<input name="comments" type="text" value="What are your goals?" onfocus="if(this.value == 'What are your goals?') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'What are your goals?'; }" />
<div class="g-recaptcha" data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxxxxx"></div>
</li>
<li>
<input type="submit" value="SUBMIT" class="submitbtn" form="contact" />
</li>
</form>

Related

PHP form with checkbox and verification does't work

i"m new here and i don't understand php at all, but i need to do a contact form with checkbox and verification, this is my code ( is a frankenstein code).
I need that my form send an email with the information avoiding spam, and missing information, and when mail arrive has all the details in header like a mail to reply, subject and all.
if you can post an correct code will be wonderful.
thanks in advance
<form name="htmlform" method="post" action="app.php">
<label for="name">*Nombre Completo</label>
<input type="text" name="name" maxlength="150" size="50">
<label for="company">*Empresa</label>
<input type="text" name="company" maxlength="150" size="50">
<label for="telephone">Teléfono</label>
<input type="text" name="telephone" maxlength="150" size="50">
<label for="email">*Email</label>
<input type="text" name="email" maxlength="180" size="50">
<label for="services">*Servicios de Interes</label>
<input type="checkbox" name="services[]" value="apps" />apps<br />
<input type="checkbox" name="services[]" value="Marketing Movil" />Marketing Móvil<br />
<input type="checkbox" name="services[]" value="video juegos" />video Juegos<br />
<label for="comments">*Comentarios</label>
<textarea name="comments" maxlength="1000" cols="40" rows="6"></textarea>
<div class="hide">Leave this empty:<input name="url" /></div>
<center><input class="button large" type="submit" value="Submit Form"></center>
</form>
<?php
// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == '')
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "my#mail.com";
$email_subject = "Contact from web.com";
function died($error) {
// your error code can go here
echo "There were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['full_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['services']) ||
!isset($_POST['comments']))
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$full_name = $_POST['full_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$services = $_POST['services']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$full_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($full_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Services: ".clean_string($services)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
// hacker defense
function clean($var){//request string cleaner
if(get_magic_quotes_gpc()) $var=stripslashes($var); //clean
$var=mysql_real_escape_string($var); //clean
return strip_tags($var, '<b><a>');//returning clean var
}
function hackerDefense(){//thanks to Allen Sanford
// begin hacker defense
foreach ($_POST as &$postvalue){ //checking posts
$postvalue = clean($postvalue);//cleaning the value
}
} // end hacker defense
?>
<!-- include your own success html here -->
<center>
<img src="images/logo.png" />
<br>
<br>
Thank you for contacting us. We will be in touch.<br>
<br>
HOME</center>
<?php
}
?>

Contact Form working in Chrome, not in IE/Firefox

Having some trouble with the contact form on my website, http://www.techcom.co.nz/
It works fine on google chrome, however on IE and Firefox it doesn't send any message and just redirects back up to the top of the page/refreshes the page.
Here is the php code for the form:
// EDIT THE FOLLOWING LINE BELOW AS REQUIRED
$send_email_to = "techcomnz#gmail.com";
function send_email($name,$email,$email_subject,$email_message)
{
global $send_email_to;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$email. "\r\n";
$message = "<strong>Email = </strong>".$email."<br>";
$message .= "<strong>Name = </strong>".$name."<br>";
$message .= "<strong>Message = </strong>".$email_message."<br>";
#mail($send_email_to, $email_subject, $message,$headers);
return true;
}
function validate($name,$email,$message,$subject)
{
$return_array = array();
$return_array['success'] = '1';
$return_array['name_msg'] = '';
$return_array['email_msg'] = '';
$return_array['message_msg'] = '';
$return_array['subject'] = '';
if($email == '')
{
$return_array['success'] = '0';
$return_array['email_msg'] = 'email is required';
}
else
{
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$return_array['success'] = '0';
$return_array['email_msg'] = 'enter valid email.';
}
}
if($name == '')
{
$return_array['success'] = '0';
$return_array['name_msg'] = 'name is required';
}
else
{
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
$return_array['success'] = '0';
$return_array['name_msg'] = 'enter valid name.';
}
}
if($subject == '')
{
$return_array['success'] = '0';
$return_array['subject_msg'] = 'subject is required';
}
if($message == '')
{
$return_array['success'] = '0';
$return_array['message_msg'] = 'message is required';
}
else
{
if (strlen($message) < 2) {
$return_array['success'] = '0';
$return_array['message_msg'] = 'enter valid message.';
}
}
return $return_array;
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$return_array = validate($name,$email,$message,$subject);
if($return_array['success'] == '1')
{
send_email($name,$email,$subject,$message);
}
header('Content-type: text/json');
echo json_encode($return_array);
die();
?>
and here is the html:
<fieldset id="contact_form">
<div id="msgs"> </div>
<form id="cform" name="cform" method="post" action="">
<input type="text" id="name" name="name" value="Full Name*" onfocus="if(this.value == 'Full Name*') this.value = ''"
onblur="if(this.value == '') this.value = 'Full Name*'" />
<input type="text" id="email" name="email" value="Email Address*" onfocus="if(this.value == 'Email Address*') this.value = ''"
onblur="if(this.value == '') this.value = 'Email Address*'" />
<input type="text" id="subject" name="subject" value="Subject*" onfocus="if(this.value == 'Subject*') this.value = ''"
onblur="if(this.value == '') this.value = 'Subject*'" />
<textarea id="msg" name="message" onfocus="if(this.value == 'Your Message*') this.value = ''"
onblur="if(this.value == '') this.value = 'Your Message*'">Your Message*</textarea>
<button id="submit" class="button" style=""> Send Message</button>
</form>
</fieldset>
Any help would be greatly appreciated.
Regards
Leaving the action attribute blank will cause most browsers to submit the form data to the current page by reloading it with the data in GET or POST.
If this is your intention, try removing the action="" altogether as it has been known to cause issues with older browsers.

Get multiple values of checkbox in PHP

I need help with this if any can show me, that would be so great and helpful.
I am trying to get more then one value show up through a checkbox, with this information in PHP has been sent to an email. I can get anyone on the selected list work individually when applied
This is my PHP & HTML code, it all works fine, it's just the program will only send one of the selected list, even if I select more then one.
$ch1, $ch2, $ch3, $ch4 ,$ch5
PHP
<?php
if(isset($_POST['email'])) {
$email_to = "";
$email_subject = "";
function died($error) {
// Error Code
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstname']) ||
!isset($_POST['lastname']) ||
!isset($_POST['checkboxes']) ||
!isset($_POST['gender']) ||
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
!isset($_POST['telephone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$firstname = $_POST['firstname']; // required
$lastname = $_POST['lastname']; // required
$ch1 = 'unchecked'; // required
$ch2 = 'unchecked'; // required
$ch3 = 'unchecked'; // required
$ch4 = 'unchecked'; // required
$ch5 = 'unchecked'; // required
$male_status = 'unchecked'; // required
$female_status = 'unchecked'; // required
$email_from = $_POST['email']; // required
$subject = $_POST['subject']; // required
$telephone = $_POST['telephone']; // required
$message = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$firstname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$lastname)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$subject)) {
$error_message .= 'The Subject you entered does not appear to be valid.<br />';
}
if (isset($_POST['checkboxes'])) {
$selected_checkboxes = $_POST['checkboxes'];
if (isset($_POST['ch1'])) {
$ch1 = $_POST['checkboxes'];
if ($ch1 == 'googlechrome') {
$ch1 = 'checked';
}
}
if (isset($_POST['ch2'])) {
$ch2 = $_POST['checkboxes'];
if ($ch2 == 'firefox') {
$ch2 = 'checked';
}
}
if (isset($_POST['ch3'])) {
$ch3 = $_POST['checkboxes'];
if ($ch3 == 'safari') {
$ch3 = 'checked';
}
}
if (isset($_POST['ch4'])) {
$ch4 = $_POST['checkboxes'];
if ($ch4 == 'internetexplorer') {
$ch4 = 'checked';
}
}
if (isset($_POST['ch5'])) {
$ch5 = $_POST['checkboxes'];
if ($ch5 == 'opera') {
$ch5 = 'checked';
}
}
}
if (isset($_POST['gender'])) {
$selected_radio = $_POST['gender'];
if ($selected_radio == 'male') {
$male_status = 'checked';
}
else if ($selected_radio == 'female') {
$female_status = 'checked';
}
}
if(strlen($message) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($firstname)."\n";
$email_message .= "Last Name: ".clean_string($lastname)."\n";
$email_message .= "Gender: ".clean_string($selected_radio)."\n";
$email_message .= "Telephone: ".clean_string($telephone).
"\n";
$email_message .= "Email: ".clean_string($email_from).
"\n";
$email_message .= "Subject: ".clean_string($subject).
"\n";
$email_message .= "Browsers Used: ".clean_string($selected_checkboxes)."\n";
$email_message .= "Message: ".clean_string($message).
"\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
HTML
<form id="contact" name="contact" action="contact.php" method="post">
<p>
<label for="firstname">First Name *<br>
</label>
<input type="text" name="firstname" maxlength="50" size="30" id="firstname" placeholder="First Name" required autofocus>
<label for="lastname"><br>
<br>
Last Name *<br>
</label>
<input type="text" name="lastname" maxlength="50" size="30" id="lastname" placeholder="Last Name" required>
<label for="email"><br>
<br>
Email Address *<br>
</label>
<input type="text" name="email" maxlength="80" size="30" id="email" placeholder="example#domain.com" required>
<label for="telephone"><br>
<br>
Telephone <br>
</label>
<input type="text" name="telephone" maxlength="30" size="30" id="subject" placeholder="Phone Number" required>
<br>
<br>
<label for="subject">Subject *</label>
<br>
<input type="text" name="subject" maxlength="30" size="30" id="subject" placeholder="Hello" required>
<br>
<br>
<Input type = "Radio" Name ="gender" value= "Male">Male
<Input type = "Radio" Name ="gender" value= "Female" >Female
<br>
</p>
<p>"What browser are you using, to view this website"<br>
<Input type = "Checkbox" Name ="checkboxes" value="Google Chrome">Google Chrome
<Input type = "Checkbox" Name ="checkboxes" value="Firefox">Firefox
<Input type = "Checkbox" Name ="checkboxes" value="Safari">Safari
<Input type = "Checkbox" Name ="checkboxes" value="Internet Explorer" >Internet Explorer
<Input type = "Checkbox" Name ="checkboxes" value="Opera" >Opera
<br>
<br>
Message *<br>
</label>
<textarea name="message" maxlength="1000" cols="90" rows="6" id="message" placeholder="Type message here" required></textarea>
<br>
<input type="submit" value="Submit">
</p>
</form>
<Input type = "Checkbox" Name ="checkboxes[]" value="Google Chrome">Google Chrome
<Input type = "Checkbox" Name ="checkboxes[]" value="Firefox">Firefox
<Input type = "Checkbox" Name ="checkboxes[]" value="Safari">Safari
<Input type = "Checkbox" Name ="checkboxes[]" value="Internet Explorer" >Internet Explorer
<Input type = "Checkbox" Name ="checkboxes[]" value="Opera" >Opera
The correct way to do this is to give your checkboxes different names.
<input type="checkbox" name="chrome" value="Google Chrome" />Chrome
<input type="checkbox" name="firefox" value="Firefox" />Firefox
<input type="checkbox" name="safari" value="Safari" />Safari
<input type="checkbox" name="ie" value="Internet Explorer" />IE
<input type="checkbox" name="opera" value="Opera" />Opera
Just FYI, the <label> tag is pretty useful here, so the text will be "tied" to the box when you click or hover.
<label for='cb1'>
<input id='cb1' type = "Checkbox" name ="chrome" value="Google Chrome" />Chrome
</label>
You can style it like
label:hover { background:orange; }
This also works for radio buttons.
Also, it's a good idea to avoid mixing up uppercase and lowercase of your attributes (the type, name, etc. are called attributes). You want everything in lowercase whenever possible.
If you changes the name parameter in your html to checkboxes[]:
<Input type = "Checkbox" Name ="checkboxes[]" value="Google Chrome">Google Chrome
<Input type = "Checkbox" Name ="checkboxes[]" value="Firefox">Firefox
<Input type = "Checkbox" Name ="checkboxes[]" value="Safari">Safari
<Input type = "Checkbox" Name ="checkboxes[]" value="Internet Explorer" >Internet Explorer
<Input type = "Checkbox" Name ="checkboxes[]" value="Opera" >Opera
Then $_POST['checkboxes'] will contain an array of the selected values.
Note that it won't return anything for the checkboxes that weren't selected, so you'll need to keep track of all values to compare to what was selected.

PHP, Not able to send Emails

I would like to have a contact form on my that requires the *fullname, *email address, and *subject and *message. I followed a tutorial to develop my form but for some reason it is not sending my test message.
I'm not experienced enough with PHP to figure out what I am doing wrong, so I am hoping to get suggestions on how to resolve this issue. All questions, suggestions, and possible solutions are welcome. Thanks.
contact form php:
Code:
<?php
// EDIT THE FOLLOWING LINE BELOW AS REQUIRED
$send_email_to = "jb#me.com";
function send_email($name,$email,$email_subject,$email_message)
{
global $send_email_to;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$email. "\r\n";
$message = "<strong>Email = </strong>".$email."<br>";
$message .= "<strong>Name = </strong>".$name."<br>";
$message .= "<strong>Message = </strong>".$email_message."<br>";
#mail($send_email_to, $email_subject, $message,$headers);
return true;
}
function validate($name,$email,$message,$subject)
{
$return_array = array();
$return_array['success'] = '1';
$return_array['name_msg'] = '';
$return_array['email_msg'] = '';
$return_array['message_msg'] = '';
$return_array['subject'] = '';
if($email == '')
{
$return_array['success'] = '0';
$return_array['email_msg'] = 'email is required';
}
else
{
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$return_array['success'] = '0';
$return_array['email_msg'] = 'enter valid email.';
}
}
if($name == '')
{
$return_array['success'] = '0';
$return_array['name_msg'] = 'name is required';
}
else
{
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name)) {
$return_array['success'] = '0';
$return_array['name_msg'] = 'enter valid name.';
}
}
if($subject == '')
{
$return_array['success'] = '0';
$return_array['subject_msg'] = 'subject is required';
}
if($message == '')
{
$return_array['success'] = '0';
$return_array['message_msg'] = 'message is required';
}
else
{
if (strlen($message) < 2) {
$return_array['success'] = '0';
$return_array['message_msg'] = 'enter valid message.';
}
}
return $return_array;
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$return_array = validate($name,$email,$message,$subject);
if($return_array['success'] == '1')
{
send_email($name,$email,$subject,$message);
}
header('Content-type: text/json');
echo json_encode($return_array);
die();
?>
Contact Form HTML:
Code:
<fieldset id="contact_form">
<div id="msgs"> </div>
<form id="cform" name="cform" method="post" action="">
<input type="text" id="name" name="name" value="Full Name*" onfocus="if(this.value == 'Full Name*') this.value = ''"
onblur="if(this.value == '') this.value = 'Full Name*'" />
<input type="text" id="email" name="email" value="Email Address*" onfocus="if(this.value == 'Email Address*') this.value = ''"
onblur="if(this.value == '') this.value = 'Email Address*'" />
<input type="text" id="subject" name="subject" value="Subject*" onfocus="if(this.value == 'Subject*') this.value = ''"
onblur="if(this.value == '') this.value = 'Subject*'" />
<textarea id="msg" name="msg" onfocus="if(this.value == 'Your Message*') this.value = ''"
onblur="if(this.value == '') this.value = 'Your Message*'">Your Message*</textarea>
<button id="submit" class="button"> Send Message</button>
</form>
</fieldset>
Your form's action isn't set to anything. You'll need to point it at the script you have there that sends the email.
Ie:
<form id.. name.. method.. action="/handle_post.php">
Set the correct action and then try it should work..
if it still does not work test it with curl utility to see if ur script is fine..
One more mistake that i saw was that ur text area form name is msg while on server ur expecting ur post request it have message. That wont work..
If u still face problem then we wd debug further :)
First you need to set action to some script that will handle $_POST inputs (contactform.php) or $_SERVER['PHP_SELF'] for the same file.
Second you should send data by input type=submit not button.

Error Paging - Echo to HTML Page

Hello,
I am wondering HOW I can have any and all errors (when the form is submitted) link to a general error page "Link an error.html". The php form I am using now, links to itself and is just an ugly page with no css formatting. Do I need the echos to link to an "error.html"?
I am working with the following HTML FORM :
<div id="contact">
<form name="contactform" method="post" action="send_form_email.php">
<label for="first_name">First <span class="red">*</span></label>
<input type="text" name="first_name" maxlength="50" size="30">
<label for="last_name">Last <span class="red">*</span></label>
<input type="text" name="last_name" maxlength="50" size="30">
<label for="email">Email <span class="red">*</span></label>
<input type="text" name="email" maxlength="80" size="30">
<label for="telephone">Telephone</label>
<input type="text" name="telephone" maxlength="30" size="30">
<label for="comments">Message <span class="red">*</span></label>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
<input type="submit" value="Send Message">Email Form
</form>
</div>
This is the PHP File that I am Using :
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info#glustik.com";
$email_subject = "Project Quote Request";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- MY THANK YOU SUCCESS PAGE GOES HERE -->
<?php
}
?>
It is better to show the form validation errors along with the form. That way the user will get direct feedback.
You can use an array for all error messages.
<?php
$errors = array();
if(!isset($_POST['email'])) {
$errors['email'] = 'Email is required';
}
//similarly for other errors.
Now in the form
<input type="text" name="last_name" maxlength="50" size="30">
<label for="email">Email <span class="red">*</span></label>
<?= if(isset($errors['email'])) echo $errors['email'] ?>

Categories