Simpletest PHP scriptable browser… how to test submit a form that has [ ] in the form name (basically in array format)?

情到浓时终转凉″ 提交于 2019-12-11 14:21:33

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/3173870/simpletest-php-scriptable-browser-how-to-test-submit-a-form-that-has-in-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!