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

StackOverflow https://stackoverflow.com/questions/3173870

  •  02-10-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top