PDA

View Full Version : HTML/php Email Form - Doesn't fully work when edited



Spikey247
Jun 18th, 2017, 07:53 PM
Hello,

I used a template to create a contact form for my site, which works absolutely fine!

However, i tried to edit it slightly to work as a booking form too, but now it doens't want to work, and i'm sure that somewhere i have missed out something or forgotten to change a label, but i can't seem to see it. Can I have a fresh pair of eyes from someone who knows more than I do (which would be most of you i'm sure) to help me try and work out what's happened please?

Here is the first WORKING contact form, for your reference. You can see it working here (http://skillatarms.co.uk/contactform.php)(please don't spam it!) (and I know it is partially php, please don't kill me if this is in the wrong section). If you want the code for it posted on this forum, just let me know!

Now, here is the link to the form that isn't working - Contact Form - Skill at Arms (http://skillatarms.co.uk/bookingform.php).
Here is the code for the website:


<head>
<link href="css/bookingform.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1 style="font-family: Helvetica, Verdana, Geneva, Tahoma, sans-serif;">Request your Booking</h1>
<form method="post" action="send_contactform_email.php" class="cf">
<div class="half left cf">
<input name="firstname" type="text" id="input-firstname" placeholder="First Name *">
<input name="lastname" type="text" id="input-lastname" placeholder="Last Name *">
<input name="email" type="email" id="input-email" placeholder="Email address *">
<input name="mobile" type="text" id="input-mobile" placeholder="Mobile Number *">
<input name="attendees" type="text" id="input-attendees" placeholder="Number of Guests *">
<input name="coupon" type="text" id="input-coupon" placeholder="Coupon/Gift Code">
</div>
<div class="half right cf">
<select name="bookingtype" id="input-bookingtype">
<option value="none" selected>Please select a booking type</option>
<option value="rifle">Rifle Shooting Experience (59)</option>
<option value="extended">Extended Experience (25)**</option>
</select>
<select name="bookingdate" id="input-bookingdate">
<option value="none" selected>Please select a booking date</option>
<option value="22/07/2017">22nd July 2017 - Limited spaces avaliable!</option>
<option value="05/08/2017">5th August 2017</option>
<option value="09/09/2017">9th September 2017</option>
<option value="10/09/2017">10th September 2017</option>
<option value="07/10/2017">7th October 2017</option>
<option value="08/10/2017">8th October 2017</option>
</select>
<textarea name="message" type="text" id="input-message" placeholder="Any Information/Requests"></textarea>
</div>
<input type="submit" value="Submit" id="input-submit">
</form>

</body>

Here is the CSS if you want/need it:


@charset "utf-8";
/* CSS Document */

@import url(http://fonts.googleapis.com/css?family=Merriweather);
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

html, body {
font-family: 'Merriweather', sans-serif;
padding: 1em;
}

h1 {
text-align: center;
color: #000000;
text-shadow: 1px 1px 0 white;
font-family: cool_crayon, Verdana, Geneva, sans-serif
}

form {
max-width: 600px;
text-align: center;
margin: 20px auto;
}
form select {
border: 0;
outline: 0;
padding: 1em;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
display: block;
width: 100%;
margin-top: 1em;
font-family: 'Merriweather', sans-serif;
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
resize: none;
}
form select:focus {
-moz-box-shadow: 0 0px 2px #e74c3c !important;
-webkit-box-shadow: 0 0px 2px #e74c3c !important;
box-shadow: 0 0px 2px #e74c3c !important;
}

form input, form textarea {
border: 0;
outline: 0;
padding: 1em;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
display: block;
width: 100%;
margin-top: 1em;
font-family: 'Merriweather', sans-serif;
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
resize: none;
}
form input:focus, form textarea:focus {
-moz-box-shadow: 0 0px 2px #e74c3c !important;
-webkit-box-shadow: 0 0px 2px #e74c3c !important;
box-shadow: 0 0px 2px #e74c3c !important;
}

form #input-submit {
color: white;
background: #25524D;
cursor: pointer;
font-size: large;
}
form #input-submit:hover {
-moz-box-shadow: 0 1px 1px 1px rgba(170, 170, 170, 0.6);
-webkit-box-shadow: 0 1px 1px 1px rgba(170, 170, 170, 0.6);
box-shadow: 0 1px 1px 1px rgba(170, 170, 170, 0.6);
}
form textarea {
height: 213px;
}

.half {
float: left;
width: 48%;
margin-bottom: 1em;
}

.right {
width: 50%;
}

.left {
margin-right: 2%;
}

@media (max-width: 480px) {
.half {
width: 100%;
float: none;
margin-bottom: 0;
}
}
/* Clearfix */
.cf:before,
.cf:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}

.cf:after {
clear: both;
}

aaaaand finally, here is the script to send the email and verify the inputs:


<?php

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



// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "[email protected]";

$email_subject = "Booking Request Submission";





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['firstname']) ||

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

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

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

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

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

!isset($_POST['attendees'])) {

died('We are sorry, but there appears to be a problem with the form you submitted.');

}



$firstname = $_POST['firstname']; // required

$lastname = $_POST['lastname']; // required

$email = $_POST['email']; // required

$mobile = $_POST['mobile']; // required

$attendees = $_POST['attendees']; // required

$bookingtype = $_POST['bookingtype']; // required

$bookingdate = $_POST['bookingdate']; // required


$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email)) {

$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 />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$lastname)) {

$error_message .= 'The last name you entered does not appear to be valid.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}
$email_message = "Booking Form Submission.\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 .= "Email: ".clean_string($email)."\n";

$email_message .= "Mobile Number: ".clean_string($mobile)."\n";

$email_message .= "Number of Guests: ".clean_string($attendees)."\n";

$email_message .= "Message: ".clean_string($message)."\n";

$email_message .= "Coupon: ".clean_string($coupon)."\n";

$email_message .= "Booking Type: ".clean_string($bookingtype)."\n";

$email_message .= "Booking Date: ".clean_string($bookingtype)."\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 your own success html here -->



<center>
<p style="font-size:large; font-family: Helvetica, Verdana, Geneva, Tahoma, sans-serif;"><b>Thank you for sending us a booking request! We will be in touch soon!</b><br /><br />
<img src="images/saa_logo_black_900w.png" width="800" height="135" /></p>
</center>


<?php
header( "refresh:10; url=contactform.php" );
?>



<?php

}

?>


Any and all help will be greatly appreciated. Thank You in advance - Please tell me i'm being stupid! :o

Jai

sunfighter
Jun 18th, 2017, 08:31 PM
There are things on the web page that a "view page source" does not show like Mobile Number, Number of Guests, Coupon/...... . Where does that come from ? Why can't I see it?

Please post the PHP code your using.

Spikey247
Jun 18th, 2017, 08:36 PM
The php code is in the first post, or are you after the one for the contact form that works? Or is there something I am doing wrong that you need that I am forgetting about?

Spikey247
Jun 18th, 2017, 08:37 PM
17196

Spikey247
Jun 19th, 2017, 11:19 AM
Please help. I'm completely stumped. It must be something in the php code that isn't working or I've missed out :(
Thanks in advance. Jai

CFMaBiSmAd
Jun 19th, 2017, 02:35 PM
First of all, the doctype you are using on the page doesn't match the html markup, so, I'm surprised either page works. I recommend that you validate your pages at validator.w3.org and if you are going to use html5 markup, use the html5 doctype.

Did you change the action='....' attribute in the form tag so that it points to the booking php page, because the posted code appears like it is still trying to submit to the contact form php page?

Next, what exact symptom or error are you getting that leads you to believe something isn't working?

Lastly, the php code you found is insecure, needlessly cluttered, nonsense, and I/we wish people would quit copying crap found on the web and expect someone else to tell them why it isn't working. Well written code is self-troubleshooting and will tell you when, where, and why it isn't working.

sunfighter
Jun 19th, 2017, 07:39 PM
Add to all that, The site you directed us to has this address "http://skillatarms.co.uk/bookingform.php" which is a PHP file. We can not read that file So please post THAT code, here.