I am working on a website for a real estate agency. There is one page called the details.php page, here customers can see all the characteristics of a house that they are looking for. I have a contact form on this page for a customer to fill in when he/she is interested.
If I go to www.mywebsite.com/details.php, this contact form works as it should work, I receive the email with all the contact information.
Now when a real customer uses the webpage he/she will never go to the www.mywebsite.com/details.php instead it will look like: www.mywebsite.com/properties/house-for-sale-in-London/6227.php (just an example of a property)
Here is where the contact form breaks, it shows in the URL bar all the information that was filled in like this:
www.mywebsite.com/properties/house-for-sale-in-London/6227.php?action=submit&name=TEST&telefono=TEST%40test.com&email=test%40test.com&message=Etoy+interesado+en+ver+este+inmueble.+Por+favor+contáctame.&subnewtide=Submit
but it doesn´t send, neither does it echo the thank you message.
What did I do wrong?
This is the code:
<h3>¿Quieres más información?</h3>
<form role="form" class="form-b">
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<div class="contact-form">
<form action="" id="form-anchor" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit"> Mi nombre:
<br>
<input name="name" type="text" value="" size="30" />
<br> Mi numero:
<br>
<input name="telefono" type="text" value="" size="30" />
<br> Mi correo:
<br>
<input name="email" type="text" value="" size="30" />
<br> Mensaje:
<br>
<textarea name="message" rows="3" cols="30">Estoy interesado en ver este inmueble. Por favor contáctame.</textarea>
<br>
<div class="enviar-button">
<input type="submit" class="btn btn-block btn-primary" name="subnewtide" id="subnewtide" value="Submit" />
</div>
</form>
</div>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$telefono=$_REQUEST['telefono'];
$message=$_REQUEST['message'];
$info= "Nombre: .$name. \r\n";
$info.= "Email: $email \r\n";
$info.= "telefono: $telefono \r\n";
$info.= "Codigo: $codigo \r\n";
if (($name=="")||($email=="")||($message=="")||($telefono==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("[email protected]", $subject, $info, $message);
echo '<div class="gracias">Gracias por contactarnos, pronto un asesor atenderá tu solicitud.</div>';
}
}
?>
</form>
echo $actionto see what it prints.postso you may be thinking first form will use get method and second form will usepostmethod?, answer is stop thinking like that, you can not override the method in the from, it will always use the first form method, and in your case itsget, so you always going to see the infomration in url, Second you should not use the nested form, read the link for more information w3.org/TR/html5/forms.html#the-form-element