Web Design Forum: Complete nightmare contact form! - 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

Complete nightmare contact form! Rate Topic: -----

#1 User is offline   jame5payne 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 48
  • Joined: 02-December 11
  • Reputation: 0

Posted 22 December 2011 - 10:09 PM

I am hoping and preying that someone will help me as I've been banging my head against a brick wall because of this.....

I'm new to php and jQuery and I'm trying to get my form to work. I've coded the HTML for the form and next I want to sort the code for PHP and validate it. Below is the HTML and PHP code I have so far for the first part of the form...
When I test this out by filling in the fields and clicking send the only fields I receive in my email are firstName_field, lastName_field, street_field and lineTwo_field.

The rest...town_field, city_field and postcode_field are all empty in my sent email...does anyone know WHY???? :help:



// PHP CODE BELOW //


<?php

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

$to = "Email address goes here";
$subject = "Title";

// data the visitor provided
$firstName_field = filter_var($_POST['firstName'], FILTER_SANITIZE_STRING);
$lastName_field = filter_var($_POST['lastName'], FILTER_SANITIZE_STRING);
$street_field = filter_var($_POST['street'], FILTER_SANITIZE_STRING);
$lineTwo_field = filter_var($_POST['lineTwo'], FILTER_SANITIZE_STRING);
$town_field = filter_var($_POST['town'], FILTER_SANITIZE_STRING);
$city_field = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
$postcode_field = filter_var($_POST['postcode'], FILTER_SANITIZE_STRING);


//constructing the message
$body = " From: $firstName_field $lastName_field\n Street: $street_field\n Address line 2: $lineTwo_field\n Town: $town_field\n City: $city_field\n Postcode: $postcode_field\n";

// ...and away we go!
mail($to, $subject, $body);

// redirect to confirmation
header('Location: thanks.html');

} else {
// handle the error somehow
}
?>



// HTML CODE BELOW //


<div id="formContainer">

<form id="quoteRequest" method="post" action="quoteRequest.php">

<div class="formDescription">
<h2>Quote Request</h2>
<p>Please complete the form below to receive a free Limousine hire quote for your requirements. You can also get a quote by calling one of our Customer Services Team on ...</p>
</div>

<!--------------------SECTION BREAK-------------------->

<div class="section_break">
<h3>Personal Details</h3>
</div>

<!--------------------NAME FIELD-------------------->

<div class="row">
<div class="label">Name *</div>
<input type="text" id="firstName" name= "firstName" class="detail" value=""/>
<label class="context">First</label>
<input type="text" id="lastName" name= "lastName" class="detail" value=""/>
<label class="context">Last</label>
</div>

<!--------------------ADDRESS FIELD-------------------->

<div class="row">
<div class="label">Address *</div>
<input type="text" name="street" class="detail" value="">
<label class="context">Street Address</label>
</div>

<div class="row">
<input type="text" name="lineTwo" class="detail" value="">
<label class="context">Address Line 2</label>
</div>

<div class="row">
<input type="text" name="town" class="detail" value="">
<label class="context">Town</label>
</div>

<div class="row">
<input type="text" name="city" class="detail" value="">
<label class="context">City</label>
</div>

<div class="row">
<input type="text" name="postcode" class="detail" value="">
<label class="context">Postcode</label>
</div>

</form>

</div>
0

#2 User is offline   simplypixie 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 23-November 11
  • Reputation: 11
  • Gender:Female
  • Location:Shropshire
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 23 December 2011 - 07:06 AM

Have you checked first that there are values in your posted data (before it even reaches sending an email). Temporarily prevent the sending of the email and echo or dump your posted data to make sure the value sare there in the first instance.

If they are then maybe it is your filter_var and/or FILTER_SANITIZE_STRING (I am not sure what you are doing with these so maybe post the code for these functions.
0

#3 User is offline   Nitin Reddy 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 55
  • Joined: 11-September 09
  • Reputation: 6
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 26 December 2011 - 10:43 AM

Hi!

@jame5payne

First off, I would suggest you use filter_input_array instead of calling filter_var on each array element because of the overhead involved in calling the function for each array element. The overhead may be insignificant and, as the expression goes, it's not going to kill bunnies anywhere, but it is good programming practice to avoid unnecessary function calls. An optimizer may be in place for function in-lining but one shouldn't rely on it being present because not all web hosting servers would have an optimizer in place.

Next, would it be possible for you to echo the contents of the variables instead of mailing them and post the output to this thread? There doesn't seem to be anything wrong with the code that you are using.

@simplypixie

filter_var is a PHP built-in function available from PHP 5.2 and FILTER_SANITIZE_STRING is a type of filter. It's a documented PHP function.
0

#4 User is offline   nfc212 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 257
  • Joined: 29-August 11
  • Reputation: 27
  • Gender:Male
  • Location:Cardiff, UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 01 January 2012 - 11:15 PM

I'm not sure how you are submitting the form as there is no submit button.

However using the code posted above, with a submit button added, the form and script works fine, all the fields are displayed in the received mail.

From: David Cameron
Street: Ivory Tower
Address line 2: Nuthatch
Town: Hicksville
City: Never land
Postcode: BU5 7ER
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