A WebTestCase example of adding a field to a form before submitting it
<?php
//
public void testAddHiddenFormField() throws Exception {
HtmlPage page = loadPage("<html><body>"
+ "<form name='myform'>"
+ "<button type='submit' id='mybutton'/>"
+ "</form>"
+ "</body></html>");
final Map nodeValues = new HashMap();
nodeValues.put("type", "hidden");
nodeValues.put("name", "hiddenName");
nodeValues.put("value", "hiddenValue");
final HtmlHiddenInput hidden = new HtmlHiddenInput(page, nodeValues);
page.getFormByName("myform").appendChild(hidden);
final HtmlButton button = (HtmlButton) page.getHtmlElementById("mybutton");
page = (HtmlPage) button.click();
assertEquals(URL_GARGOYLE + "?hiddenName=hiddenValue", page
.getWebResponse()
.getUrl()
.toExternalForm());
}