0

I am working on a site locally and I am trying to add a contact form to it.

I've added a simple form on: http:localhost:8888/testsite/contact.php, when the user clicks on the submit button I want them to be redirected to another page with a message on it. The page I want the user to go to after submitting the form it: contact_message.php.

I've created both files and they both display OK on there URLs- http:localhost:8888/testsite/contact.php and http:localhost:8888/testsite/contact-message.php however the form isn't working because when you click submit the url changes to: http:localhost:8888/testsite/contact.php/contact-message.php, which would be fine if it showed the contact-message.php content, but it doesn't.

The code fore the form is:

<form method="post" action="contact-message.php">
    <table>
        <tr>
            <th>
                <label for="name">Name</label>
            </th>
            <td>
                <input type="text" name="name" id="name">
            </td>
        </tr>
        <tr>
            <th>
                <label for="email">Email</label>
            </th>
            <td>
                <input type="text" name="email" id="email">
            </td>
        </tr>
        <tr>
            <th>
                <label for="message">Message</label>
            </th>
            <td>
                <textarea type="text" name="message" id="message"></textarea>
            </td>
        </tr>

    </table>

    <input type="submit" value="Send">

</form>

Does anybody have any ideas?

1
  • are you sure the contact-message.php script is actually working? a syntax error could kill the script before ANY output is performed, leaving you with a blank browser. e.g. do some basic debugging yourself... Commented Oct 24, 2013 at 16:11

3 Answers 3

1

You need to add a full path or relative path to the correct file in your form action. Currently, you are telling the form to submit to the current url plus contact-message.php. Instead try...

<form method="post" action="http:localhost:8888/testsite/contact-message.php">

Or simply..

<form method="post" action="/contact-message.php">

which tells it to use the base URL + /contact-message.php

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

2 Comments

If i use: <form method="post" action="/contact-message.php"> Then that makes the url http://localhost:8888/contact-message.php instead of http://localhost:8888/testsite/contact-message.php
I had no way of knowing if your base url was localhost:8888 or localhost:8888/testsite as either could be configured. In this case, you can just change it to action="/testsite/contact-message.php"
0

Try to use this code if your send mail function return true:

header("Location: http://localhost:8888/testsite/contact_message.php");

PHP header documentation: http://php.net/manual/pt_BR/function.header.php

Comments

0

try replacing the form tag with:

<form method="post" action="./contact-message.php">

This will then call the contact-message.php file that is located in the same folder. The dot is the beginning f a relative path starting at the current position

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.