最简单的PHP可编写脚本脚本的浏览器...如何测试提交表单名称中具有[]的表单(基本上为数组格式)? [英] Simpletest PHP scriptable browser... how to test submit a form that has [ ] in the form name (basically in array format)?
问题描述
我使用的是simpletest,可编写脚本的php浏览器,并尝试测试提交的数组格式表单,如下所示:
I am using simpletest, the php scriptable browser and trying to test submit a form that is in array format so its like this:
<input id="password" name="session[password]" value="" type="password">
其他输入名称均以会话"开头,因此我必须给出每个输入的全名,但是当我在PHP脚本中执行以下操作时,它似乎不起作用:
Other input names start with "session" so I have to give the full name of each but it doesn't seem to work when I do it like this in my PHP script:
$this->setField('session[password]', 'password');
我想知道是否有人知道正确执行此操作的方法,或者我可以将其设置为查看输入的id,因为据我所知,这始终是唯一的,我什至不知道为什么他们选择名称而不是ID作为此字段...
I'm wondering if anyone knows of a way to do this properly, or can I set it to look at the input's id instead, since this is always unique, as far as I know, I don't even understand why they chose name rather than ID as the field to use for this...
任何建议都将不胜感激.
Any advice is greatly appreciated.
推荐答案
您可以通过查看$_POST["session"]["password"]
来获得用户提交的值(假设表单方法是"post",而不是"get").
You get the value the user has submitted by looking at $_POST["session"]["password"]
(assuming the form method was "post", not "get").
您可以使用以下简单脚本对其进行测试:
You can test it with this simple script:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<pre>";
var_dump($_POST);
die();
}
?>
<form method="post">
<input id="password" name="session[password]" value="" type="password">
<input type="submit" />
</form>
这篇关于最简单的PHP可编写脚本脚本的浏览器...如何测试提交表单名称中具有[]的表单(基本上为数组格式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!