根据用户需求添加文字输入
<form action = "numbericalInput.php" method = "Get">
Please enter the number of input areas you wish
<input type = "text" name = "amountOfEntry"/>
<input type = "submit" name = "GO"/>
</form>
<?php
if(!empty($_GET("amountOFEntry")){
for($i = 0; $i < $_GET("amountOFEntry"); $i++){
<input type= "text" name = "nums[]" size = "2" />
}
}
?>
我想做的是要求用户在文本区域中输入一个值,然后我向他们提供适当数量的文本输入,供他们输入值。因此,用户输入 10,他们有提供 10 个文本输入和一个提交按钮或其他东西。我很欣赏这条线在原来的地方行不通,
<input type= "text" name = "nums[]" size = "2" />
但我确信这是正确的?另外,这条线有什么问题吗?
if(!empty($_GET("amountOFEntry")){
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用: isset() http://php.net/manual/en/function.isset.php
这将检查 $_GET 是否存在[ 'amountOFEntry'] (注意方括号,因为 $_GET 和 $_POST 是数组)
另请注意使用 ++$i 而不是 $i++。这里的性能略有提升。不多,但值得做。
编辑:::
请注意,变量将区分大小写,您在表单中使用 amountOfEntry 并在循环中使用 $_GET['amountOFEntry'] 。 (注意国会大厦F)
use: isset() http://php.net/manual/en/function.isset.php
This will check for the existence of $_GET['amountOFEntry'] (Note square brackets as $_GET and $_POST are arrays)
Please also note use of ++$i instead of $i++. There is a minor performance increase here. Not much but it worth doing.
EDIT:::
Please note that the variables will be case sensitive, You are using amountOfEntry in the form and $_GET['amountOFEntry'] in the loop. (Note capitol F)
$_GET 是一个数组,必须使用 [] 来获取元素。所以:
$_GET is an array, you have to use [] to get the elements. So:
正如所指出的,$_GET 返回一个值数组。因此,请使用方括号来查找所需的变量。而且你不能混合 HTML 和 PHP。因此,您需要将 HTML 设为字符串(通过引用它),然后用户 echo(或 print)来输出该字符串。
另外,正如 Lizard 所指出的,您应该使用 isset 来确定变量是否已设置。
As pointed out $_GET returns an array of values. So use the square brackets to find the variable you want. Also you cant mix HTML amd PHP. So you need to make the HTML a string (by quoting it) and user echo (or print) to output the string.
Also, as noted by Lizard, you should use isset to determine if the variable is set.
您不妨获取 $_GET 的数值以避免运行时错误:
You might as well get the numerical value of the $_GET to avoid runtime errors:
如果您愿意,可以使用 JavaScript。使用像 JQuery 这样的库会有很大帮助。
JavaScript:
HTML:
这需要大量工作,只是为了避免将页面发送回服务器并在服务器端执行工作,但我想我还是建议这样做......
If you preferred you could use JavaScript. Using a library like JQuery would help a lot.
JavaScript:
HTML:
This is a lot of work just to avoid sending the page back to the server and having the work carried out on the server-side, but thought I might suggest it anyway...