PK333
PK333

Reputation: 147

PHP URL redirection

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?

Upvotes: 0

Views: 437

Answers (3)

Charlie Martin
Charlie Martin

Reputation: 8406

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

Upvotes: 1

T3 H40
T3 H40

Reputation: 2436

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

Upvotes: 0

thiagobraga
thiagobraga

Reputation: 1561

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

Upvotes: 0

Related Questions