duanche4578 2013-10-24 16:08
浏览 17
已采纳

PHP URL重定向

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?

  • 写回答

3条回答 默认 最新

  • douyanpeng0748 2013-10-24 16:13
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?