Form sends GET instead of POST

后端 未结 2 771
陌清茗
陌清茗 2020-12-19 01:33

I have searched the all questions with similar title, no solution for me yet.

I have a website running on apache2. I need to submit sensitive information through a

相关标签:
2条回答
  • 2020-12-19 01:54

    If like me you gone from Routed url (like in Laravel) to plain PHP, and wonder why the file /user/store/index.php responds that it receives a GET request using:

    <form method="POST" action="/user/store">
      <input type="text" id="user_name" name="user_name" />
      <button type="submit">Create a new user</button>
    </form>
    

    Just check it again... Yes you forgot a trailing slash... so /user/store will receives only get, while /user/store/ will receive what you form requested.

    Edit

    I inspected what Laravel does, and it solves this particular issue with this addition in their .htaccess (check the original file).

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    
    0 讨论(0)
  • 2020-12-19 01:58

    One way to solve this is to reinforce your intentions by expliciting formmethod="post", like this:

    <button type="submit" formmethod="post" formaction="add_user.php">Submit</button>
    
    0 讨论(0)
提交回复
热议问题