|
From: <x03...@ya...> - 2010-02-11 16:29:51
|
I read in the archives that hidden fields generate a request every couple of months. Maybe mine can be the one for this bi-monthly period.
I've read about the workaround but that doesn't seem to work for me and I haven't been able to figure it out.
I have a simple form which you can see here:
http://giganto-corp.com/st/test.php
It has 2 fields: a visible name field and a hidden field named 'secret'. When you fill out the name and submit, the page just repaints with the name you entered and the 'secret' value below the form.
Here is the test
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
require_once '../lib/simpletest/autorun.php';
require_once '../lib/simpletest/unit_tester.php';
require_once '../lib/simpletest/web_tester.php';
class AllTests extends WebTestCase {
function testForm() {
$this->assertTrue($this->get("http://localhost/st/test.php"));
$this->assertText('My Form');
$this->setField('name','charlie');
$this->click('Go',array('secret'=>'word'));
$this->assertText('charlie');
$this->assertText('word');
}
}
?>
I set the name to 'charlie' and on the submit I set the 'secret' value to 'word'. The subsequent test for 'charlie' passes, but the test for 'word' fails. If I change the last test to look for 'junk', which is the default value of the hidden field, the test passes.
Where have I screwed up?
BTW, here is the code for the form:
<?php
$name = $_POST['name'];
$hidden = $_POST['secret'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<title>Simpletest Problem</title>
</head>
<body>
<h1>My Form</h1>
<form id="my-upload-form" action="test.php" method="post"
enctype="multipart/form-data" >
<input type="text" name="name"/>
<input type="hidden" name="secret" value="junk"/>
<input type="submit" name="submit-button" value="Go"/>
</form>
<h1>Previous Values</h1>
Name: <?php echo $name; ?><br />
Hidden: <?php echo $hidden; ?>
</body>
</html>
|