0

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>
5
  • Why do yo have a form inside another one? Have you tried to echo $action to see what it prints. Commented Jun 16, 2016 at 23:09
  • Also your form is a POST method. why you supposed to see the information in the url? why not try $_POST['action'] Commented Jun 16, 2016 at 23:17
  • Your another form is inside another form, and first form is using get method, which is default, and second form is using post so you may be thinking first form will use get method and second form will use post method?, 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 its get, 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 Commented Jun 17, 2016 at 0:08
  • Thanks for the info, I will have a look today and post back. Commented Jun 17, 2016 at 13:17
  • Thanks guys, your comments made me see my mistake! Commented Jun 17, 2016 at 13:30

1 Answer 1

1

First of all if you're using POST method in the form parameters shouldn't be sent through the url. Now one of the issues might be the fact that you have a form nested in the form so it might take the first form element as the valid one and GET is the default method. So see if that might be the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, I never realized I had a form inside of a form. I think it happened because I was replacing an old form with a new one. It now works after removing the form b part. Thanks again for showing my blindspot!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.