2

I'm trying to submit a simple form that has an array of fields:

<form>
<input type='text' name='Article[]' id='Article1' />
<input type='text' name='Article[]' id='Article2' />
<input type='text' name='Article[]' id='Article3' /> 

So, how do I set the different fields using SimpleTest?

(p.s. I've seen this question: Simpletest PHP scriptable browser... how to test submit a form that has [ ] in the form name (basically in array format)? but it doesn't answer my question).

4

3 回答 3

1

I figured out one way of doing this is to use setFieldById. Change the code to:

$form->setFieldById('Article1', 'Some Article Text 1'); 
$form->setFieldById('Article2', 'Some Article Text 2'); 

And so on. Works perfectly but assumes you can generate unique IDs for each field -- not that difficult.

于 2011-07-05T04:06:53.443 回答
0

Try $form->setField('Article', array("Some article text", "Some article text2"));

于 2011-07-01T07:26:50.363 回答
-2

Try this: (simpletest.php)

<?php
if( isset( $_REQUEST['submit']))
    print_r( $_POST['Article']);
?>
<form method='post' action='simpletest.php'> 
<input type='text' name='Article[]' id='Article1' />
<input type='text' name='Article[]' id='Article2' />
<input type='text' name='Article[]' id='Article3' />
<input type='submit' name='submit' id='submit' />
</form>
于 2011-07-01T06:32:09.220 回答