html - Html Form 发送字符串而不是数组
问题描述
I can not send an array to the server through an html form with method post, when the amount of selected checkboxes is only one. 在任何其他情况下,如果元素的数量超过一个,它可以正常工作,并且表单会向我发送一个包含这些元素(字符串)的数组。所以问题是当用户只选择一个元素时,表单会发送一个字符串而不是一个字符串的数组。我该如何解决这个问题,以便向我发送一个包含一个元素(字符串)的数组?
是的,你是对的,我必须提供我的代码,顺便说一下,它在 bootstrap 4.0 中
<form method="post">
<div class="form-group">
<label for="myVariable">Choose :</label>
<div class="form-check">
<div>
<input class="form-check-input" name="myVariable" id="idOfChoice1" type="checkbox" value="valueOfChoice1" >
<label class="form-check-label">
choice1
</label>
</div>
<div>
<input class="form-check-input" name="myVariable" id="idOfChoice2" type="checkbox" value="valueOfChoice2" >
<label class="form-check-label">
choice2
</label>
</div>
</div>
</div>
<button type="submit" id="sendDataToServer" class="btn btn-primary">Submit</button>
</form>
因此,在上面的代码中,如果我选择两个复选框,我会在服务器端得到一个包含两个字符串的数组,顺便说一下,它在 expressjs 中。当我只选中一个复选框而不是一个数组时,我得到一个字符串而不是一个带字符串的数组。谢谢你。
解决方案
本质上,您只需将其称为$form_input=$array[0]
.
如果这不是您想要的,请给我们一些代码示例并告诉我们您正在使用哪种编程语言,以便我们可以(更好地)帮助您。
推荐阅读
- python - sqlite3.OperationalError:“创建”附近:语法错误
- deep-learning - 标记所有可见对象以进行对象检测是否重要?
- teradata - Teradata 存储过程
- jmeter - 如何在 loadrunner 中传递随机特定值..?
- c# - 如何从命令行使用 PHP 中的会话?
- nativescript - Objective-C 在 Nativescript 中编组“可选”属性的问题
- python - PI 小数点后第 n 位
- java - 如何执行存储在 Java 上的 String 变量中的多个请求?
- excel - VBA - 日期时间字符串替换/替换
- sql - 如何在postgresql的查询中一起转换列和函数之间的使用