Source for file form.php
Documentation is available at form.php
* Base include file for SimpleTest.
* @version $Id: form.php 1672 2008-03-02 04:47:34Z edwardzyang $
* include SimpleTest files
require_once(dirname(__FILE__
) .
'/tag.php');
require_once(dirname(__FILE__
) .
'/encoding.php');
require_once(dirname(__FILE__
) .
'/selector.php');
* Form tag class to hold widget values.
* Starts with no held controls/widgets.
* @param SimpleTag $tag Form tag to read.
* @param SimplePage $page Holding page.
$this->_method =
$tag->getAttribute('method');
$this->_encoding =
$this->_setEncodingClass($tag);
$this->_id =
$tag->getAttribute('id');
* Creates the request packet to be sent by the form.
* @param SimpleTag $tag Form tag to read.
* @return string Packet class.
function _setEncodingClass($tag) {
if (strtolower($tag->getAttribute('method')) ==
'post') {
if (strtolower($tag->getAttribute('enctype')) ==
'multipart/form-data') {
return 'SimpleMultipartEncoding';
return 'SimplePostEncoding';
return 'SimpleGetEncoding';
* Sets the frame target within a frameset.
* @param string $frame Name of frame.
* Accessor for method of form submission.
* @return string Either get or post.
* Combined action attribute with current location
* to get an absolute form target.
* @param string $action Action attribute from form tag.
* @param SimpleUrl $base Page location.
* @return SimpleUrl Absolute form target.
if (($action ===
'') ||
($action ===
false)) {
return $page->expandUrl($page->getUrl());
return $page->expandUrl(new SimpleUrl($action));;
* Absolute URL of the target.
* @return SimpleUrl URL target.
* Creates the encoding for the current values in the
* @return SimpleFormEncoding Request to submit.
$encoding =
new $class();
for ($i =
0, $count =
count($this->_widgets); $i <
$count; $i++
) {
* ID field of form for unique identification.
* @return string Unique tag ID.
* Adds a tag contents to the form.
* @param SimpleWidget $tag Input tag to add.
if (strtolower($tag->getAttribute('type')) ==
'submit') {
} elseif (strtolower($tag->getAttribute('type')) ==
'image') {
} elseif ($tag->getName()) {
* Sets the widget into the form, grouping radio
* @param SimpleWidget $tag Incoming form control.
function _setWidget(&$tag) {
if (strtolower($tag->getAttribute('type')) ==
'radio') {
$this->_addRadioButton($tag);
} elseif (strtolower($tag->getAttribute('type')) ==
'checkbox') {
$this->_addCheckbox($tag);
* Adds a radio button, building a group if necessary.
* @param SimpleRadioButtonTag $tag Incoming form control.
function _addRadioButton(&$tag) {
if (! isset
($this->_radios[$tag->getName()])) {
* Adds a checkbox, making it a group on a repeated name.
* @param SimpleCheckboxTag $tag Incoming form control.
function _addCheckbox(&$tag) {
$this->_widgets[$index]->addWidget($previous);
$this->_widgets[$index]->addWidget($tag);
* Extracts current value from form.
* @param SimpleSelector $selector Criteria to apply.
* @return string/array Value(s) as string or null
for ($i =
0, $count =
count($this->_widgets); $i <
$count; $i++
) {
if ($selector->isMatch($this->_widgets[$i])) {
if ($selector->isMatch($button)) {
return $button->getValue();
* Sets a widget value within the form.
* @param SimpleSelector $selector Criteria to apply.
* @param string $value Value to input into the widget.
* @return boolean True if value is legal, false
* otherwise. If the field is not
* present, nothing will be set.
function setField($selector, $value, $position=
false) {
for ($i =
0, $count =
count($this->_widgets); $i <
$count; $i++
) {
if ($selector->isMatch($this->_widgets[$i])) {
if ($position ===
false or $_position === (int)
$position) {
if ($this->_widgets[$i]->setValue($value)) {
* Used by the page object to set widgets labels to
* @param SimpleSelector $selector Criteria to apply.
for ($i =
0, $count =
count($this->_widgets); $i <
$count; $i++
) {
if ($selector->isMatch($this->_widgets[$i])) {
* Test to see if a form has a submit button.
* @param SimpleSelector $selector Criteria to apply.
* @return boolean True if present.
if ($selector->isMatch($button)) {
* Test to see if a form has an image control.
* @param SimpleSelector $selector Criteria to apply.
* @return boolean True if present.
foreach ($this->_images as $image) {
if ($selector->isMatch($image)) {
* Gets the submit values for a selected button.
* @param SimpleSelector $selector Criteria to apply.
* @param hash $additional Additional data for the form.
* @return SimpleEncoding Submitted values or false
* if there is no such button
$additional =
$additional ?
$additional :
array();
if ($selector->isMatch($button)) {
$encoding =
$this->_encode();
$button->write($encoding);
$encoding->merge($additional);
* Gets the submit values for an image.
* @param SimpleSelector $selector Criteria to apply.
* @param integer $x X-coordinate of click.
* @param integer $y Y-coordinate of click.
* @param hash $additional Additional data for the form.
* @return SimpleEncoding Submitted values or false
* if there is no such button in the
function submitImage($selector, $x, $y, $additional =
false) {
$additional =
$additional ?
$additional :
array();
foreach ($this->_images as $image) {
if ($selector->isMatch($image)) {
$encoding =
$this->_encode();
$image->write($encoding, $x, $y);
$encoding->merge($additional);
* Simply submits the form without the submit button
* value. Used when there is only one button or it
* @return hash Submitted values.
Documentation generated on Sun, 04 May 2008 09:21:37 -0500 by phpDocumentor 1.3.0