I have created a form using PHP. and I am unable to receive all the forms fields .. only message the message field input is receiving to my email.
Below is my code.
[B]
form.php
[CODE]
<?php include(‘form_process.php’); ?>
=
<link rel=”stylesheet” href=”form.css” type=”text/css”>
<div class=”container”>
<form id=”contact” action=”<?= htmlspecialchars($_SERVER[“PHP_SELF”]) ?>” method=”post”>
<h3>Contact</h3>
<h4>Contact us today, and get reply with in 24 hours!</h4>
<fieldset>
<input placeholder=”Your name” type=”text” name=”name” value=”<?= $name ?>” tabindex=”1″ autofocus>
<span class=”error”><?= $name_error ?></span>
</fieldset>
<fieldset>
<input placeholder=”Your Email Address” type=”text” name=”email” value=”<?= $email ?>” tabindex=”2″>
<span class=”error”><?= $email_error ?></span>
</fieldset>
<fieldset>
<input placeholder=”Your Phone Number” type=”text” name=”phone” value=”<?= $phone ?>” tabindex=”3″>
<span class=”error”><?= $phone_error ?></span>
</fieldset>
<fieldset>
<fieldset>
<textarea value=”<?= $message ?>” name=”message” tabindex=”4″ placeholder=”No of adults, No of children and Date for ride” >
</textarea>
</fieldset>
<fieldset>
<button name=”submit” type=”submit” id=”contact-submit” data-submit=”…Sending”>Submit</button>
</fieldset>
<div class=”success”><?= $success ?></div>
</form>
</div>
[B]
form_process.php
[CODE]
<?php
// define variables and set to empty values
$name_error = $email_error = $phone_error = “”;
$name = $email = $phone = $message = $success = “”;
//form is submitted with POST method
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
if (empty($_POST[“name”])) {
$name_error = “Name is required”;
} else {
$name = test_input($_POST[“name”]);
// check if name only contains letters and whitespace
if (!preg_match(“/^[a-zA-Z ]*$/”,$name)) {
$name_error = “Only letters and white space allowed”;
}
}
if (empty($_POST[“email”])) {
$email_error = “Email is required”;
} else {
$email = test_input($_POST[“email”]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email_error = “Invalid email format”;
}
}
if (empty($_POST[“phone”])) {
$phone_error = “Phone is required”;
} else {
$phone = test_input($_POST[“phone”]);
// check if e-mail address is well-formed
if (!preg_match(“/^(d[s-]?)?[([s-]{0,2}?d{3}[)]s-]{0,2}?d{3}[s-]?d{4}$/i”,$phone)) {
$phone_error = “Invalid phone number”;
}
}
if (empty($_POST[“message”])) {
$message = “”;
} else {
$message = test_input($_POST[“message”]);
}
if ($name_error == ” and $email_error == ” and $phone_error == ”){
$message_body = ”;
unset($_POST[‘submit’]);
foreach ($_POST as $key => $value){
$message_body .= “$key: $valuen”;
$phone.=”$KEY: $value”;
}
$to = ‘[email protected]’;
$subject = ‘Contact Form Submit’;
‘Reply-To: [email protected]’;
if (mail($to, $subject, $message) ){
$success = “Message sent, thank you for contacting us!”;
$name = $email = $phone = $message = ”;
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
A help is much appreciated ..
Thanks