Simpletest PHP 可编写脚本的浏览器...如何测试提交表单名称中包含 [ ] 的表单(基本上采用数组格式)?

发布于 2024-09-08 07:05:13 字数 427 浏览 1 评论 0原文

我正在使用 simpletest,php 可编写脚本的浏览器,并尝试测试提交一个数组格式的表单,如下所示:

<input id="password" name="session[password]" value="" type="password">

其他输入名称以“session”开头,所以我必须给出每个名称的全名,但似乎没有当我在 PHP 脚本中这样做时,

$this->setField('session[password]', 'password');

我想知道是否有人知道正确执行此操作的方法,或者我可以将其设置为查看输入的 id,因为这始终是唯一的,就我知道,我什至不明白为什么他们选择名称而不是 ID 作为用于此目的的字段......

非常感谢任何建议。

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">

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');

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

虚拟世界 2024-09-15 07:05:13

您可以通过查看 $_POST["session"]["password"] 获取用户提交的值(假设表单方法是“post”,而不是“get”)。

您可以使用这个简单的脚本来测试它:

<?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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文