- <?
- /**
- * @package form
- * @filesource
- * @see HTML_FORM_COMPONENT_PATH.'/Form.php'
- * @copyright (c) http://Finn-Rasmussen.com
- * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
- * @author http://Finn-Rasmussen.com
- * @version 1.9
- * @since 21-oct-2005
- */
-
- /**
- * The required files
- */
- require_once(HTML_PATH.'/Html.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Label.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Input.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/TextField.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Disabled.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Readonly.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Hidden.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Button.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Password.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/ResetButton.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/CancelButton.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/SubmitButton.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/ImageButton.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Radio.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Checkbox.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Select.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Option.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Textarea.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Zip.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Fileupload.php');
- if (defined('HTML_BASE_UTIL_PATH')) {
- require_once(HTML_BASE_UTIL_PATH.'/Fieldset.php');
- require_once(HTML_BASE_UTIL_PATH.'/Legend.php');
- }
-
- /**
- * Generates a html form
- * <code>
- * Usage:
- * $form = new Form('goHere.php','get');
- * $form->add(new SubmitButton($action,$method,$name,$attr,$title,$onsubmit));
- * print $form->getHtml();
- * Or:
- * Form::start($action,$method,$name,$attr,$title,$onsubmit);
- * elements::display()
- * Form::end();
- * Or:
- * Form::start($action,$method,$name,$attr,$title,$onsubmit);
- * Form::textarea();
- * Form::submitbutton();
- * :
- * Form::end();
- * </code>
- * @package form
- */
-
- class Form extends Html {
- var $action = ''; // Where to go
-
- var $method = ''; // How to send data POST/GET
-
- var $name = ''; // The name of the form (NOT xhtml 1.0 strict compliant)
-
- var $id = ''; // The id of the form (NOT netscape 4.x compliant)
-
- var $attr = ''; // Additional attributes for the form
-
- var $title = ''; // The title (tooltip) of the form
-
- var $onsubmit = ''; // Onsubmit event
-
-
-
- /**
- * Constructor
- * @param String $action The action where to go, default 'self'
- * @param String $method The method get/post
- * @param String $name The name if any (NOT xhtml 1.0 strict compliant)
- * @param String $attr Additional attributes, i.e. 'enctype="multipart/form-data"'
- * @param String $title The title (tooltip)
- * @param String $onsubmit The onsubmit event
- */
- function Form($action='',$method='',$name='',$attr='',$title='',$onsubmit='') {
- $this->Html();
- $this->action = $action!=''?$action:$_SERVER['PHP_SELF'];
- $this->method = $method!=''?$method:'get';
- $this->name = $name!=''?$name:'';
- $this->id = $name!=''?$name:'';
- $this->attr = $attr!=''?' '.$attr:'';
- $this->title = $title!=''?$title:'';
- $this->onsubmit = $onsubmit!=''?$onsubmit:'';
- }
-
- /**
- * Returns the html for the hidden fields of a form
- * @return String The html
- */
- function getHidden() {
- $html = '';
- // GET
- if (defined('REQUEST_LANGUAGE') && !empty($_GET[REQUEST_LANGUAGE])) {
- $hidden = new Hidden(REQUEST_LANGUAGE,$_GET[REQUEST_LANGUAGE]);
- $html .= $hidden->getHtml();
- }
- if (defined('REQUEST_TAB') && !empty($_GET[REQUEST_TAB])) {
- $hidden = new Hidden(REQUEST_TAB,$_GET[REQUEST_TAB]);
- //$html .= $hidden->getHtml();
- }
- if (defined('REQUEST_SID') && !empty($_GET[REQUEST_SID])) {
- $hidden = new Hidden(REQUEST_SID,$_GET[REQUEST_SID]);
- $html .= $hidden->getHtml();
- }
-
- // POST
- if (defined('REQUEST_LANGUAGE') && !empty($_POST[REQUEST_LANGUAGE])) {
- $hidden = new Hidden(REQUEST_LANGUAGE,$_POST[REQUEST_LANGUAGE]);
- $html .= $hidden->getHtml();
- }
- if (defined('REQUEST_TAB') && !empty($_POST[REQUEST_TAB])) {
- $hidden = new Hidden(REQUEST_TAB,$_POST[REQUEST_TAB]);
- //$html .= $hidden->getHtml();
- }
- if (defined('REQUEST_SID') && !empty($_POST[REQUEST_SID])) {
- $hidden = new Hidden(REQUEST_SID,$_POST[REQUEST_SID]);
- $html .= $hidden->getHtml();
- }
- if ($html!='') {
- $html = '<p>'.$html."</p>\r\n";
- }
- return $html;
- }
-
- /**
- * Returns the html for the start of a form
- * @return String The html
- */
- function getStart() {
- $html = '';
- $html .= '<form';
- $html .= $this->getAttribute('action');
- $html .= $this->getAttribute('method');
- $html .= $this->getAttribute('name'); // NOT xhtml 1.0 strict compliant
- $html .= $this->getAttribute('id'); // NOT netscape 4.x compliant
- $html .= $this->getAttribute('title');
- $html .= $this->getAttribute('onsubmit');
- $html .= $this->attr; // more attributes, if required
- $html .= '>'."\r\n";
- $html .= $this->getHidden();
- return $html;
- }
-
- /*
- * Returns the html for the end of a form
- * @return String The html
- */
- function getEnd() {
- return "</form>\r\n";
- }
-
- /*
- * Get the complete html for a Form
- * @return String the html
- */
- function getHtml() {
- $html = $this->html;
- $html .= $this->getStart();
- $html .= $this->getElements(); // as html
- $html .= $this->getEnd();
- return $html;
- }
-
- /**
- * Display start html
- * <code>
- * Usage:
- * Form::start($action,$method,$name,$attr,$title,$onsubmit);
- * </code>
- * @static
- * @param String $action The action where to go, default 'self'
- * @param String $method The method get/post
- * @param String $name The name if any (NOT xhtml 1.0 strict compliant)
- * @param String $attr Additional attributes, i.e. 'enctype="multipart/form-data"'
- * @param String $title The title (tooltip)
- * @param String $onsubmit The onsubmit event
- */
- function start($action='',$method='',$name='',$attr='',$title='',$onsubmit='') {
- switch ($action) {
- case 'fieldset':
- Fieldset::start($action,$method);
- break;
- default:
- $html = new Form($action,$method,$name,$attr,$title,$onsubmit);
- $html->addHtml($html->getStart());
- break;
- }
- }
-
- /**
- * Display end html
- * <code>
- * Usage:
- * Form::end($element);
- * </code>
- * @static
- */
- function end($element='') {
- switch ($element) {
- case 'fieldset':
- Fieldset::end();
- break;
- default:
- $html = new Html();
- $html->addHtml(Form::getEnd());
- break;
- }
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::display($name,$class,$attr);
- * </code>
- * @static
- * @param String $action The action where to go, default 'self'
- * @param String $method The method get/post
- * @param String $name The name if any (NOT xhtml 1.0 strict compliant)
- * @param String $attr Additional attributes, i.e. 'enctype="multipart/form-data"'
- * @param String $title The title (tooltip)
- * @param String $onsubmit The onsubmit event
- */
- function display($action='',$method='',$name='',$attr='',$title='',$onsubmit='') {
- $html = new Form($action,$method,$name,$attr,$title,$onsubmit);
- $html->addHtml($html->getHtml());
- }
-
- // *********** FORM ELEMENTS ***********
-
-
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::selectstart($name,$class,$attr);
- * </code>
- * @static
- * @param String $name The name of the control
- * @param String $class The class name
- * @param String $attr Additional atributes
- */
- function selectstart($name,$class='',$attr='') {
- Select::start($name,$class,$attr);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::option($text,$value,$selected);
- * </code>
- * @static
- * @param String $text the text to show
- * @param String $value the value, if any
- * @param String $selected The option is selected
- */
- function option($text,$value='',$selected='') {
- Option::display($text,$value,$selected);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::selectend();
- * </code>
- * @static
- */
- function selectend() {
- Select::end();
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::label($text,$id,$class);
- * </code>
- * @static
- * @param String $text the text to show
- * @param String $id the ID for the control to relate to
- * @param String $class the class name
- */
- function label($text,$id='',$class='') {
- Label::display($text,$id,$class);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::legend($text,$class,$accesskey);
- * </code>
- * @static
- * @param String $text The text to show
- * @param String $class The class name
- * @param String $accesskey The access key
- */
- function legend($text,$class='',$accesskey='') {
- Legend::display($text,$class,$accesskey);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::fieldsetstart($legend,$class);
- * </code>
- * @static
- * @param String $legend The legend object to use
- * @param String $class The css class of the link
- */
- function fieldsetstart($legend='',$class='') {
- Fieldset::start($legend,$class);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::fieldsetend();
- * </code>
- * @static
- */
- function fieldsetend() {
- Fieldset::end();
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::textarea($name,$text='',$rows='',$cols='',$class='');
- * </code>
- * @static
- * @param String $name The name of the control
- * @param String $text The text value, if any
- * @param String $rows The number of rows
- * @param String $cols The number of columns
- * @param String $class The class name
- */
- function textarea($name,$text='',$rows='',$cols='',$class='') {
- Textarea::display($name,$text,$rows,$cols,$class);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::input($type,$name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- * </code>
- * @static
- * @param String $type the type (text, radio, checkbox, file, button, hidden, submit, reset)
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $size the size / or checked for radio/checkbox
- * @param String $maxlength the maxlength
- * @param String $disabled the disabled
- * @param String $readonly the readonly
- * @param String $onclick On click event for javascript
- */
- function input($type,$name='',$value='',$class='',$size='',$maxlength='',$disabled='',$readonly='',$onclick='') {
- Input::display($type,$name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::textfield($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $size the size
- * @param String $maxlength the maxlength
- * @param String $disabled the disabled
- * @param String $readonly the readonly
- * @param String $onclick On click event for javascript
- */
- function textfield($name='',$value='',$class='',$size='',$maxlength='',$disabled='',$readonly='',$onclick='') {
- TextField::display($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::disabled($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $size the size
- * @param String $maxlength the maxlength
- * @param String $disabled the disabled
- * @param String $readonly the readonly
- * @param String $onclick On click event for javascript
- */
- function disabled($name='',$value='',$class='',$size='',$maxlength='',$disabled='',$readonly='',$onclick='') {
- Disabled::display($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::readonly($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $size the size
- * @param String $maxlength the maxlength
- * @param String $disabled the disabled
- * @param String $readonly the readonly
- * @param String $onclick On click event for javascript
- */
- function readonly($name='',$value='',$class='',$size='',$maxlength='',$disabled='',$readonly='',$onclick='') {
- Readonly::display($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::password($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $size the size
- * @param String $maxlength the maxlength
- * @param String $disabled the disabled
- * @param String $readonly the readonly
- * @param String $onclick On click event for javascript
- */
- function password($name='',$value='',$class='',$size='',$maxlength='',$disabled='',$readonly='',$onclick='') {
- Password::display($name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::hidden($name,$value);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- */
- function hidden($name='',$value='') {
- Hidden::display($name,$value);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::button($name,$value,$class,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $onclick On click event for javascript
- */
- function button($name='',$value='',$class='',$onclick='') {
- Button::display($name,$value,$class,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::resetbutton($name,$value,$class,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $onclick On click event for javascript
- */
- function resetbutton($name='',$value='',$class='',$onclick='') {
- ResetButton::display($name,$value,$class,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::submitbutton($name,$value,$class,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $onclick On click event for javascript
- */
- function submitbutton($name='',$value='',$class='',$onclick='') {
- SubmitButton::display($name,$value,$class,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::fileupload($name,$class);
- * </code>
- * @static
- * @param String $name the name
- * @param String $class the class
- */
- function fileupload($name='',$class='') {
- SubmitButton::display($name,$class);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::cancelbuttonbutton($name,$value,$class,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $onclick On click event for javascript
- */
- function cancelbutton($name='',$value='',$class='',$onclick='') {
- CancelButton::display($name,$value,$class,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::radio($name,$value,$class,$checked);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $checked if present
- * @param String $onclick On click event for javascript
- */
- function radio($name='',$value='',$class='',$checked='',$onclick='') {
- Radio::display($name,$value,$class,$checked,$onclick);
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Form::checkbox($name,$value,$class,$checked,$onclick);
- * </code>
- * @static
- * @param String $name the name
- * @param String $value the value, if any
- * @param String $class the class
- * @param String $checked if present
- * @param String $onclick On click event for javascript
- */
- function checkbox($name='',$value='',$class='',$checked='',$onclick='') {
- Checkbox::display($name,$value,$class,$checked,$onclick);
- }
- }
- ?>