jeudi 16 avril 2015

I am trying to run a mailing form in php. This is the HTML with Bootstrap 3.0

I am doing a contact page for a site that uses framework Twitter Bootstrap 3.0. This is the HTML.



<form action="mail.php" name="contactform" method="post" id="contact-form">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="name"> Name</label>

<input id="name" class="form-control" type="text" name="name" placeholder="Enter you name" value="" required/>

</div>
<div class="form-group">
<label for="email">Email Address</label>
<div id="input_email" class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<input id="email" class="form-control" type="email" name="email" placeholder="Enter your email" value="" required />
</div>
</div>

<div class="form-group">
<label for="subject"> Subject</label>

<input id="subject" class="form-control" type="text" name="subject" placeholder="Subject"/>

</div>

</div>

<div class="col-md-6">
<div id="input_message" class="col-md-12">
<textarea id="comments" class="form-control" name="message" rows="6" placeholder="Your Suggestion ..." value="" required ></textarea>
</div>
</div>
<!-- Submit Button -->
<div class="col-md-12">

<input class="btn btn-skin pull-right" type="submit" value="submit" id="submit">
</div>

</div>

</form>


This is the PHP:



<?php
$form_htmlString = "";
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])){
$form_htmlString = "<section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><a href=\"#sitemap\" class=\"btn btn-circle\"><i class=\"fa fa-angle-double-down animated\"></i></a></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\"> Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>";
echo $form_htmlString;
}else{
$sendTo = "example@email.com";
$subject ="Mensaje de contacto";
$title = "Alguien se ha contactado con usted";
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$comments = $_POST["message"];
$message = "\nAlguien se ha contactado con usted:"."\nNombre: ".$name."\nEmail: ".$email."\nAsunto: ".$subject."\nComentarios: ".$comments;
mail($sendTo, $subject, utf8_decode($message)); $form_htmlString = "<section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>Thank you, we will answer shortly.</span> </h2><h4></h4></div><div class=\"page-scroll\"><a href=\"#sitemap\" class=\"btn btn-circle\"><i class=\"fa fa-angle-double-down animated\"></i></a></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\"> We received your data. </h5> <p class=\"subtitle\"> Our agents will answer as fast as they can.</p></div></div></div></div></div></div>";
echo $form_htmlString;
}
?>


When I run the if, it should evaluate the data entered in the HTML through the ifs, and echo the html depending on the break, yet it echoes part of the php too. I have searched for solutions and I saw heredoc works, but in this case it didn't. Any clue?


Aucun commentaire:

Enregistrer un commentaire