<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package fusionLib
 * @copyright Copyright (c) 2007 - 2013 fusionLib. All rights reserved.
 * @link http://fusionlib.com
 */

/**
 * flFormElementSubmit Class
 *
 * Form submit button element, value is true if clicked else false.
 *
 * @package fusionLib
 */
class flFormElementSubmit extends flFormElement {

	/**
	 * The button caption.
	 *
	 * @var string
	 */
	protected $caption = null;

	/**
	 * Set the caption for the button.
	 *
	 * @param string $caption The caption.
	 * @return flFormElementSubmit This object.
	 */
	function setCaption($caption) {
		$this->caption = $caption;
		return $this;
	}

	/**
	 * Process the request data, normally called by the flForm::isSubmitted().
	 * Validation of the data is also performed and the results stored.
	 *
	 * @param flRequest $request The request object.
	 */
	function processRequest($request) {
		parent::processRequest($request);
		$this->value = $this->value !== null;
	}

	/**
	 * Draw the element.
	 */
	function render() {
		$html = "<input type=\"submit\" id=\"$this->name\" name=\"$this->name\"";
		if($this->caption !== null) $html .= " value=\"$this->caption\"";
		return $html . $this->attribHTML() . " />\n";
	}

	/**
	 * Generate the HTML for the elements label.
	 *
	 * @return string The label HTML.
	 */
	function getLabelHTML() {
		return '';
	}
}
