Jump to content

Contact Us Form Problem


newtotheland

Recommended Posts

Hi all, fairly new to php, using safari and firefox, copied this free form but for some reason keeps bringing this up when I submit:

 

We're sorry, but there's errors found with the form you submitted. The First Name you entered does not appear to be valid. Please go back and fix these errors.

 

Any idea why this is? Tried with both capital and lower case, website address is www.penaltysolutions.co.uk

 

html_form_send example.php

 

Thanks in advance

Edited by newtotheland
Link to comment
Share on other sites

 

 

<?php

if(isset($_POST['email'])) {

 

// CHANGE THE TWO LINES BELOW

$email_to = "admin@penaltysolutions.co.uk";

 

$email_subject = "New Entry";

 

function died($error) {

// your error code can go here

echo "We're sorry, but there's errors found with the form you submitted.<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);

?>

 

<!-- place your own success html below -->

 

<html>

<head>

<meta charset="utf-8" />

<title>Penalty Solutions Uk</title>

<link rel="stylesheet" type="text/css" href="style.css" media="all" />

</head>

<body>

<div id="header">

<div id="logo">

<a href="index.html"><img src="images/logo.jpg" alt="" /></a>

</div>

<ul>

<li><a href="index.html"><span>home</span></a></li>

<li><a href="about.html"><span>about us</span></a></li>

<li><a href="services.html"><span>services</span></a></li>

<li><a href="products.html"><span>products</span></a></li>

<li><a href="contact us1.html"><span>contact us</span></a></li>

</ul>

 

</div>

<div>

</div>

<div>

</div>

<div>

</div>

<div>

</div>

<div>

</div>

 

<DIV style="position: absolute; top:300px; left:450px; width:900px; height:45px">Thank you for contacting us. We will be in touch with you very soon.</DIV>

 

<?php

}

die();

?>

Link to comment
Share on other sites

Could be that you are referencing the POST field with the wrong index value. You should do a var_dump($_POST) to verify you are getting all the fields you think you should be getting.

 

Thanks Psycho that made sense, I duplicated the "first name" index? to add a company name field and thats where error was coming from. Rectified now,

Link to comment
Share on other sites

Could be that you are referencing the POST field with the wrong index value. You should do a var_dump($_POST) to verify you are getting all the fields you think you should be getting.

The only other issue is that the file uploads arent coming through with the email, I get all other info except the file uploads.

 

heres the directions from the website I got the form from about adding a upload field, but not sure where it goes.

 

 

HTML File Upload Field (field selector)

 

Sometimes it may be good to offer your website users the option to upload a file. For this you could use the HTML field type file. If you are using this option you also need to include an additional option to the FORM tag enctype="multipart/form-data"

 

 

 

Also attached html contact page below.

 

 

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title>Penalty Solutions Uk</title>

<link rel="stylesheet" type="text/css" href="style.css" media="all" />

</head>

<body>

<div id="header">

<div style= "position:absolute; top:270px; left:930px"

<li><img border="0" src="images/contact us today.jpg"</li>

</div>

<div id="logo">

<a href="index.html"><img src="images/logo.jpg" alt="" /></a>

</div>

<ul>

<li><a href="index.html"><span>home</span></a></li>

<li><a href="about.html"><span>about us</span></a></li>

<li><a href="services.html"><span>services</span></a></li>

<li><a href="products.html"><span>info</span></a></li>

<li class="selected"><a href="contact.html"><span>contact us</span></a></li>

</ul>

 

</div>

<div id="body">

<div class="header">

<div>

<ul>

 

<form name="htmlform" method="post" action="html_form_send.php"enctype="multipart/form-data">

<table width="450px">

</tr>

<tr>

<td style= "position:absolute; top:265px; left:280px">

<label for="first_name">First Name *</label>

</td>

<td style= "position:absolute; top:285px; left:280px">

<input type="text" name="first_name" maxlength="50" size="30">

</td>

</tr>

 

<tr>

<td style= "position:absolute; top:313px; left:280px">

<label for="last_name">Last Name *</label>

</td>

<td style= "position:absolute; top:333px; left:280px">

<input type="text" name="last_name" maxlength="50" size="30">

</td>

</tr>

<tr>

<td style= "position:absolute; top:356px; left:280px">

<label for="email">Email Address *</label>

</td>

<td style= "position:absolute; top:376px; left:280px">

<input type="text" name="email" maxlength="80" size="30">

</td>

 

</tr>

<tr>

<td style= "position:absolute; top:400px; left:280px">

<label for="comname">Company name </label>

</td>

<td style= "position:absolute; top:420px; left:280px">

<input type="text" name="comname" maxlength="50" size="30">

</td>

</tr>

<tr>

<td style= "position:absolute; top:356px; left:570px">

<label for="comweb">Company website </label>

</td>

<td style= "position:absolute; top:376px; left:570px">

<input type="text" name="comweb" maxlength="50" size="30">

</td>

</tr>

<tr>

<td style= "position:absolute; top:400px; left:570px">

<label for="telephone">Telephone Number *</label>

</td>

<td style= "position:absolute; top:420px; left:570px">

<input type="text" name="telephone" maxlength="30" size="30">

</td>

</tr>

<tr>

<td style= "position:absolute; top:446px; left:280px">

<label for="comments">Description of circumstances *</label>

</td>

<td style= "position:absolute; top:469px; left:280px">

<textarea name="comments" maxlength="1000" cols="68" rows="6"></textarea>

</td>

<td style= "position:absolute; top:272px; left:570px"action="index.php" enctype="multipart/form-data">

Upload file 1: <input type="file" name="selectedfile" />

</td>

<td style= "position:absolute; top:316px; left:570px"action="index.php" enctype="multipart/form-data">

Upload file 2: <input type="file" name="selectedfile" />

</td>

</tr>

<tr>

<td style= "position:absolute; top:500px; left:930px"colspan="2" style="text-align:center">

<input type="submit" value="Submit">

</td>

</tr>

</table>

</form>

 

<div id="body">

<div class="about">

 

</div>

 

</div>

<h2></h2>

</div>

</div>

<h2></h2>

</div>

 

 

</div>

<div id="footer">

<div>

<div>

<h3>Contact us</h3>

<ul>

<li>457-380-1654 - main</li>

<li>PenaltySolutionsUK - Skype</li>

</ul>

</div>

<div>

<h3>General Info</h3>

<ul>

<li><li><a style = "font 16pt arial; color:#818a8c;"; href="products.html"><span>Costs explained</span></a></li></li>

<li><li><a style = "font 16pt arial; color:#818a8c;"; href="products.html"><span>PCN issue statistics</span></a></li></li>

</ul>

</div>

<div>

<h3>Information</h3>

<ul>

<li><a style = "font 16pt arial; color:#818a8c;"; href="about.html"><span>Methodology</span></a></li>

<li><a style = "font 16pt arial; color:#818a8c;"; href="about.html"><span>Terms and conditions</span></a></li>

</ul>

</div>

<div>

<h3>Privacy</h3>

<ul>

<li><a style = "font 16pt arial; color:#818a8c;"; href="contact.html"><span>Privacy policy</span></a></li>

<li><a style = "font 16pt arial; color:#818a8c;"; href="contact.html"><span>Data Protection Act 1998</span></a></li>

</ul>

</div>

<div>

<h3>follow us:</h3>

<a class="facebook" href="http://facebook.com/...ingsolutionsuk" target="_blank">facebook</a>

<a class="twitter" href="http://twitter.com/p...ingsolutionsuk" target="_blank">twitter</a>

</div>

</div>

<div>

<p>&copy Copyright 2012. All rights reserved</p>

</div>

</div>

</body>

 

 

</body>

 

</html>

Link to comment
Share on other sites

I don't see anything in your processing code originally posted, that is referencing the file fields you have in the form.

I havent added any, Ive tried this below

 

 

 

$email_to = "admin@penaltysolutions.co.uk";

 

$email_subject = "New Entry";

 

function died($error) {

// your error code can go here

echo "We're sorry, but there's errors found with the form you submitted.<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['comname']) ||

!isset($_POST['comweb']) ||

!isset($_POST['selectedfile1']) ||

!isset($_POST['selectedfile2']) ||

!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

$comweb = $_POST['comweb'];

$selectedfile1 = $_POST['selectedfile1'];

$selectedfile2 = $_POST['selectedfile2'];

 

 

but didnt work. Not sure if im even in the right ballpark.

Edited by newtotheland
Link to comment
Share on other sites

You don't reference file upload fields in the same manner as other form inputs. Take a look at this short tutorial: http://www.tizag.com.../fileupload.php

thanks, Im reviewing it now, gonna have to get my head around it, my php file is called html_send_form.php and I already see the 1st prob in html below

 

</td>

<td style= "position:absolute; top:272px; left:570px"action="index.php" enctype="multipart/form-data">

Upload file 1: <input type="file" name="selectedfile" />

</td>

<td style= "position:absolute; top:316px; left:570px"action="index.php" enctype="multipart/form-data">

Upload file 2: <input type="file" name="selectedfile" />

</td>

 

appreciate the time psycho :)

Link to comment
Share on other sites

. . . I already see the 1st prob in html below

 

Ah, I missed that you had the enctype parameter in the TD tags, but I saw you did have it in the form tag. It probably doesn't do anything to have it in the TD tags since there is no enctype parameter for those. The problem is you are not referencing the uploads correctly - they are not in the $_POST global, they are in the . . . wait for it . . . $_FILES global. But, please read that tutorial because they are in sub-arrays - not like normal POST values.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.