samedi 18 avril 2015

Can not get a form to connect using Bootstrap and PHP [on hold]

I'm a PHP newbie and am trying to get a Bootstrap form to send to an external email address, but when the button is clicked the form will not send,validate or return an error as it should.HTML seems ok.Is the problem with the PHP?



<?php
if ($_POST["submit"]) {
$title = $_POST['title'];
$fname = $_POST['fname'];
$surname = $_POST['surname'];
$contactno = $_POST['contactno'];
$email = $_POST['email'];
$roomno = $_POST['roomno'];
$address = $_POST['address'];
$town = $_POST['town'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$floorplan = $_POST['floorplan'];
$from = 'sentMessage';
$to = 'example@.com';
$subject = 'Quote Request';
$body ="From: $title\n fname : $surname\n conatctno : $email\n roomno : $address\n town : $county\n postcode : \n $floorplan";

// Check if First name has been entered
if (!$_POST['fname']) {
$errfname = 'Please enter your First name';
}

// Check if surname has been entered
if (!$_POST['surname']) {
$errsurname = 'Please enter your Surname';
}

// Check if contact number has been entered
if (!$_POST['contactno']) {
$errcontactno = 'Please enter your number';
}

// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$erremail = 'Please enter a valid email address';
}
// Check if address has been entered
if (!$_POST['address']) {
$erraddress = 'Please enter your Address';
}

// Check if town/city has been entered
if (!$_POST['town']) {
$errtown = 'Please enter your Town/City';
}

// Check if county has been entered
if (!$_POST['county']) {
$errcounty = 'Please enter your County';
}

// Check if postcode has been entered
if (!$_POST['postcode']) {
$errpostcode = 'Please enter your postcode';
}


// If there are no errors, send the email
if (!$errfname && !$errsurname && !$errcontactno &&!$erremail &&!$erraddress &&!$errtown &&!$errcounty &&!$errpostcode) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! We will be in touch shortly</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error. Please try again.</div>';
}
}
}
?>



<div class="container">
<div class="row">


<br />

<form name="sentMessage" id="contactForm" role="form" method="post" action="quotemail.php">


<div class="form-group">
<div class="col-sm-2">
<select class="form-control" id="title" name="title">
<option><i>Title*</i></option>
<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
<option>Dr</option>
</select>


</div>
</div>
<div class="form-group">
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="First name *" id="fname" name="fname" value="<?php echo htmlspecialchars($_POST['fname']); ?>">
<?php echo "<p class='text-danger'>$errfname</p>";?>
</div>
</div>

<div class="form-group">
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="Surname *" id="surname" name="surname" value="<?php echo htmlspecialchars($_POST['surname']); ?>">
<?php echo "<p class='text-danger'>$errsurname</p>";?>
</div>
</div>

<div class="form-group">
<div class="col-sm-6">
<input type="tel" class="form-control" placeholder="Contact Number *" id="contactno" name="contactno" value="<?php echo htmlspecialchars($_POST['contactno']); ?>">
<?php echo "<p class='text-danger'>$contactno</p>";?>

</div>
</div>
<div class="form-group">
<div class="col-sm-6">

<input type="email" class="form-control" placeholder="Email *" id="email" name="email" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$erremail</p>";?>
</div>
</div>
<br />


<br />

<!-- personal details end -->




<!-- property details start -->
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h4 class="text-muted">Property Details</h4>
</div>
</div>
</div>
<!-- personal details start -->


<div class="form-group">
<div class="col-sm-2">
<select class="form-control" id="roomno" name="roomno">
<option><i>No of bedrooms*</i></option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7 or more</option>
</select>


</div>
</div>

<div class="form-group">
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="Address*" id="address" name="address" value="<?php echo htmlspecialchars($_POST['address']); ?>">
<?php echo "<p class='text-danger'>$erraddress</p>";?>
</div>
</div>

<div class="form-group">
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="Town/City *" id="town" name="town" value="<?php echo htmlspecialchars($_POST['town']); ?>">
<?php echo "<p class='text-danger'>$errtown</p>";?>
</div>
</div>


<div class="form-group">
<div class="col-sm-2">
<select class="form-control" id="floorplan" name="floorplan">
<option><i>Floorplan*</i></option>
<option>Yes</option>
<option>No</option>
</select>


</div>
</div>

<div class="form-group">
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="County*" id="County" name="county" value="<?php echo htmlspecialchars($_POST['county']); ?>">
<?php echo "<p class='text-danger'>$errcounty</p>";?>

</div>
</div>

<div class="form-group">
<div class="col-sm-5">

<input type="text" class="form-control" placeholder="Postcode *" id="postcode" name="postcode" value="<?php echo htmlspecialchars($_POST['postcode']); ?>">
<?php echo "<p class='text-danger'>$errpostcode</p>";?>
</div>
</div>



<!-- property details end -->

<div class="clearfix"></div>
<div class="col-sm-12 text-center">
<div id="success"></div>

<input id="submit" name="submit" type="submit" value="Send" class="btn btn-xl">
</div>
</div>

<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>

</form>
</div>

</di

Aucun commentaire:

Enregistrer un commentaire