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?
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
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
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 fa relative path starting at the current position
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.