php - 即使我添加了名称,HTML 表单也不起作用
问题描述
我正在用 HTML 制作表单,但遇到了这个错误:
<form action="/Profile/new/poll/posted" method="post">
<input class="hover-edit h2 hor-center" id="title" title="Poll's title ('New Poll' is not allowed)" value="New Poll" style="position: relative;text-align: center;width:95%;margin-top:2%;">
<hr>
<p><label for="opt1">Option 1</label> <input type="radio" disabled class="option"><input type="text" class="hover-edit" style="margin-top:1%;margin-bottom:1%;" name="opt1" id="opt1" value="Option 1"> <button type="button">Disable</button></button></p>
<p><label for="opt2">Option 2</label> <input type="radio" disabled class="option"><input type="text" class="hover-edit" style="margin-top:1%;margin-bottom:1%;" name="opt2" id="opt2" value="Option 2"> <button type="button">Disable</button></button></p>
<p><label for="opt3">Option 3</label> <input type="radio" disabled class="option"><input type="text" class="hover-edit" style="margin-top:1%;margin-bottom:1%;" name="opt3" id="opt3" value="Option 3"> <button type="button">Disable</button></button></p>
<p><label for="opt4">Option 4</label> <input type="radio" disabled class="option"><input type="text" class="hover-edit" style="margin-top:1%;margin-bottom:1%;" name="opt4" id="opt4" value="Option 4"> <button type="button">Disable</button></button></p>
<p><label for="opt5">Option 5</label> <input type="radio" disabled class="option"><input type="text" class="hover-edit" style="margin-top:1%;margin-bottom:1%;" name="opt5" id="opt5" value="Option 5"> <button type="button">Disable</button></button></p>
<button type="submit" class="signupbtn" style="margin:2%;width:96%;">Post</button>
</form>
上面的代码有一个表单、一些标签和一些带有名称的文本输入。但是,在操作页面上,它们都没有被定义。我尝试查看 $_POST 但仍然没有。更具体地说,我使用了:
$opt1 = $_POST["opt1"];
$opt2 = $_POST["opt2"];
$opt3 = $_POST["opt3"];
$opt4 = $_POST["opt4"];
$opt5 = $_POST["opt5"];
echo $opt1;
echo $opt2;
echo $opt3;
echo $opt4;
echo $opt5;
但是 PHP 对我代码中的每一行都返回了警告。
解决方案
表单中禁用的输入元素永远不会被提交。正如@delboy1978uk 指出的那样https://www.w3schools.com/tags/att_input_disabled.asp
所以而不是
<p><label for="opt1">Option 1</label> <input type="radio" disabled class="option"><input type="text" class="hover-edit" style="margin-top:1%;margin-bottom:1%;" name="opt1" id="opt1" value="Option 1"> <button type="button">Disable</button></button></p>
写
<p><label for="opt1">Option 1</label> <input type="radio" class="option hover-edit" style="margin-top:1%;margin-bottom:1%;" name="opt1" id="opt1" value="Option 1"/></p>
顺便说一句,我不确定我是否理解您的代码,您有标签,然后是输入(收音机),然后是输入(文本),然后是按钮,然后是关闭按钮标签。
如果你用输入打开一个标签,你用输入关闭<input type="button"></input>
,如果你用按钮关闭按钮<button></button>
,不要混合这两个标签,这是不一样的。
推荐阅读
- c# - 在 .Net Core 项目中使用利用旧样式“appSettings”的库
- ios - 删除字符串开头的非字母字符
- mysql - 给出日期的时间
- laravel - 当输入是数组时,Laravel 中的“存在”验证问题
- python - 如何获取不在 Discord 公会中的用户的用户名?
- linq - WhenAll 结果异步中的 Distinct/GroupBy
- c++ - 防止编译器分离函数的指令
- odoo - AssertionError: Element odoo has extra content: 记录,第 3 行 - - - Odoo13
- c# - 即使数据发生变化,使用实时数据库也能获得相同的结果
- ios - 将 IndexPath 行值传递给委托函数而不是 Sender.tag 以删除图像项 CollectionView Swift