开发者

Submit an array of values with SimpleTest

开发者 https://www.devze.com 2023-03-16 10:53 出处:网络
I\'m trying to submit a simple form that has an array of fields: <form> <input type=\'text\' name=\'Article[]\' id=\'Article1\' />

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' na开发者_C百科me='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).


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号