英文:
HTML form POST method transformed into GET method
问题
我有一个非常神秘的问题,导致每个<form method="POST">
在单个文件上都无法正常工作,由于某种原因,POST方法被转换为GET方法,使表单元素无效。我不知道是否被授权,但我制作了一个关于这个“问题”的视频这里,因为没有人真正理解我在说什么。
如果您有关于为什么在测试文件夹上可以工作,但在管理文件夹上不工作的潜在想法,即使两个代码都相同,请告诉我。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="POST" action="php/SetSanction.php">
<div>
<div>
<div>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;">
<div class="form-group">
<label for="daySelect">Day:</label>
<select class="form-control" name="daySelect" id="daySelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
<div class="form-group">
<label for="monthSelect">Month:</label>
<select class="form-control" name="monthSelect" id="monthSelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<details>
<summary>英文:</summary>
I have a very mysterious problem make every `<form method="POST">` not working on a single file, for x reason the POST method get transformed into a GET method making the form element useless. I don't know if it's authorized but i make a video about this "problem" [here][1] since no one really understand what i'm meanning.
If you have potential idea why it is working on the test folder but not on the admin folder even if both code are the same please let me know it.
[1]: https://streamable.com/7pggj6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="POST" action="php/SetSanction.php">
<div>
<div>
<div>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;">
<div class="form-group">
<label for="daySelect">Day:</label>
<select class="form-control" name="daySelect" id="daySelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
<div class="form-group">
<label for="monthSelect">Month:</label>
<select class="form-control" name="monthSelect" id="monthSelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
<div class="form-group">
<label for="yearSelect">Year:</label>
<select class="form-control" name="yearSelect" id="yearSelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
</div>
</div>
<div>
<label>Reason</label>
<textarea name="reasonInput" id="reasonInput" class="form-control" placeholder="..." rows="3" maxlength="400"></textarea>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Set">
</div>
</div>
</form>
</body>
</html>
And the PHP File (SetSanction.php)
<?php
print_r($_POST); // THIS ARRAY SHOULD BE EMPTY BECAUSE POST NOT WORKING
if ($_SERVER['REQUEST_METHOD'] === 'POST') /NOT WORK BECAUSE IT'S NOT POST REQ/ {
$daySelected = $_POST['daySelect'];
$monthSelected = $_POST['monthSelect'];
$yearSelected = $_POST['yearSelect'];
$reasonInput = $_POST['reasonInput'];
echo "Day: " . $daySelected . "<br>";
}
</details>
# 答案1
**得分**: 1
如果您正在重写URL以删除扩展名,这将导致表单失效,因为表单操作不会是有效的URL。
最佳选项是在`.htaccess`文件中排除表单操作URL/文件。在您的情况下,可以采取类似以下方式:
`RewriteCond %{REQUEST_URI} !^/php/SetSanction\.php$`
<details>
<summary>英文:</summary>
If you are rewriting the urls to remove the extensions, this will break the form because the form action won't be a valid url.
Best option would be to exclude the form action url / file from the `.htaccess` file.
Something like this in your case:
`RewriteCond %{REQUEST_URI} !^/php/SetSanction\.php$ `
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论