Source for file HTMLForm.class.php
Documentation is available at HTMLForm.class.php
* Note: If you include a html form, you don't need to include any form item
* classes! They will be all included.
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
* Including language specific messages.
include CLASSPATH. "/forms/error_messages/HTMLForm/". LANG. ".inc.php";
echo "<h3>You have to define the constant LANG!</h3>\r\n";
echo "Example for german: define( 'LANG', 'de' );\r\n";
include_once CLASSPATH. "html/ABSTHTMLTag.class.php";
* Including the class to define html tables for layouting the form.
include_once CLASSPATH. "html/HTMLTable.class.php";
* Including various functions to manipulate arrays.
include_once CLASSPATH. "core/Arrays.class.php";
* Class to create labels for form items.
include_once CLASSPATH. "forms/HTMLLabel.class.php";
include_once CLASSPATH. "forms/items/HTMLButton.class.php";
include_once CLASSPATH. "forms/items/HTMLCheckBox.class.php";
include_once CLASSPATH. "forms/items/HTMLPasswordInput.class.php";
include_once CLASSPATH. "forms/items/HTMLRadioGroup.class.php";
include_once CLASSPATH. "forms/items/HTMLRadioButton.class.php";
include_once CLASSPATH. "forms/items/DBKeyRadioGroup.class.php";
include_once CLASSPATH. "forms/items/HTMLTextArea.class.php";
include_once CLASSPATH. "forms/items/HTMLTextInput.class.php";
include_once CLASSPATH. "forms/items/HTMLFileInput.class.php";
include_once CLASSPATH. "forms/items/FileSelect.class.php";
include_once CLASSPATH. "forms/items/DateSelect.class.php";
include_once CLASSPATH. "forms/items/DBKeySelect.class.php";
include_once CLASSPATH. "forms/items/BirthdayDateTextInput.class.php";
include_once CLASSPATH. "forms/items/ColorInput.class.php";
include_once CLASSPATH. "forms/items/EMailTextInput.class.php";
include_once CLASSPATH. "forms/items/NumberTextInput.class.php";
include_once CLASSPATH. "forms/items/MultiRelationSelect.class.php";
include_once CLASSPATH. "forms/items/ResetSubmitButton.class.php";
include_once CLASSPATH. "forms/items/SubmitCancelButton.class.php";
include_once CLASSPATH. "forms/items/URLTextInput.class.php";
include_once CLASSPATH. "forms/items/TimeTextInput.class.php";
include_once CLASSPATH. "forms/items/HTMLHiddenInput.class.php";
* A class to generate forms.
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* The data target of this form.
* @var string $targetFile
* The target frame in a frameset for example.
* @var string $targetFrame
* The javascript that should be execute before submitting the form.
* @var string $onSubmitOrder
* The method in which kind the data should be send.
* The error that should be alert if some information is missing.
* @var string $js_err_msg
* Carries the beginning of the form.
* The content of the form.
* The text content before all items.
* @var string $textBeforeItems
* The text content behind all items.
* @var string $textBehindItems
* References to the form's items.
* Stores names of dummy items.
* @var array $dummy_item_arr
* References to the form's items that are required for a complete set of
* @var array $requiredItems
* Carries the error output for each required item.
* @var array $requiredItemOutputs
* References to the hidden form's items.
* @var array $hiddenFormItems
* References to the hidden form's items.
* @var boolean $no_format
* @var HTMLTable $layout_table
* @var strint $str_layout
* @var boolean $multipart
* @author Daniel Plücken <daniel@debakel.net>
* @param string $onSubmitOrder
* @param string $targetFile
if( !empty( $targetFile ) )
* Returns the name of this form.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the javascript that should execute on form submit.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the action-attribute of this form.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the method-attribute of this form.
* @author Daniel Plücken <daniel@debakel.net>
* Builds the tag to introduce the html form.
* @author Daniel Plücken <daniel@debakel.net>
$tmp .= "<form name=\"". $this->name. "\" "
$tmp .= " method=\"". $this->method. "\"";
? " enctype=\"multipart/form-data\""
* Adds the table by dint of the form should be formatted.
* @author Daniel Plücken <daniel@debakel.net>
* @param string|object $name
* Adds the string by dint of the form should be formatted.
* @author Daniel Plücken <daniel@debakel.net>
* @param string|object $name
* Adds references of form-items to this object.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $no_debug
echo "Check whether you had add enough items to your "
echo "There is no valid item-object reference.<br />\r\n";
echo "Proof whether you have defined enough form-items "
. "to operate the given template of the form!<br />\r\n"
. "The items which are add to the form have to have the "
. "same count of the items which are defined in the "
. "form-template.<br />\r\n";
echo "The content of variable:<br />\r\n";
echo "<b>BACKTRACE DEBUG:</b><br />\r\n";
* Returns raw data from a given request variable; Removes escapings if magic
* @author Daniel Plücken <daniel@debakel.net>
* @param string $request_input The data to be correct.
* Returns the fieldnames and values of the form by a two dimensional array.
* @author Daniel Plücken <daniel@debakel.net>
* @param array $matching_field_arr Only fields who are in this array
* will be returned. If this parameter
* isn't set, all fields and their values
$output["fields"] = array();
|| !empty( $_REQUEST[$tmp] )
if ( // Fieldnames and their values except the listed ones
$output["fields"][] = $tmp;
if ( !empty( $_FILES[$tmp]["name"] ) )
$output["fields"][] = $tmp;
$output["values"][] = $_FILES[$tmp]["name"];
$output["fields"][] = $tmp;
$output["values"][] = $this->formItems[$i]->getISODate();
$output["fields"][] = $tmp;
$output["values"][] = $this->formItems[$i]->getISOTime();
$output["fields"][] = $tmp;
$output["values"][] = $tmp_val;
$output["values"][] = $_GET[$tmp];
// DateSelect is an exception.
$tmp = $this->formItems[$i]->SETTING["instance"];
$output["fields"][] = $tmp;
$secondVar = "second". $tmp;
$minuteVar = "minute". $tmp;
$monthVar = "month". $tmp;
->SETTING["implementedSelects"]["SECOND"]
? $_POST[$secondVar] : 0;
->SETTING["implementedSelects"]["MINUTE"]
? $_POST[$minuteVar] : 0;
->SETTING["implementedSelects"]["HOUR"]
->SETTING["implementedSelects"]["DAY"]
->SETTING["implementedSelects"]["MONTH"]
->SETTING["implementedSelects"]["YEAR"]
? $_POST[$yearVar] : 1970;
->SETTING["implementedSelects"]["SECOND"]
->SETTING["implementedSelects"]["MINUTE"]
->SETTING["implementedSelects"]["HOUR"]
->SETTING["implementedSelects"]["DAY"]
->SETTING["implementedSelects"]["MONTH"]
->SETTING["implementedSelects"]["YEAR"]
? $_GET[$yearVar] : 1970;
"!^ISO!i", $this->formItems[$i]->standard_date_format
$output["values"][] = $year. "-". $month. "-". $day. " "
. $hour. ":". $minute. ":". $second;
$output["fields"][] = $tmp;
* Builds the content of this Form andstores it in the attribute form_body.
* @author Daniel Plücken <daniel@debakel.net>
* @param HTMLTable $obj_ref A reference of a table by dint of the form
* should be formatted. The form items will be
* placed in the table where the string "[item]"
* @param boolean $php_code Is this parameter true, the form items will
* be stored as the source-php-code of this
function setFormBody( $obj_ref = "", $php_code = false )
@is_a( $obj_ref[0], "HTMLTable" )
$tempCont = substr( $tempCont, 0, $tempPos )
. substr( $tempCont, $tempPos+ 6 );
$tempCont = substr( $tempCont, 0, $tempPos )
. $this->formItems[$itemCount]->get( $php_code )
. substr( $tempCont, $tempPos+ 6 );
// If the layout table is set.
->contentArr[$i][$j] = substr( $tempCont, 0, $tempPos )
->contentArr[$i][$j] = substr( $tempCont, 0, $tempPos )
* Sets the name of this form.
* @author Daniel Plücken <daniel@debakel.net>
{ $this->name = $string; }
* Sets the javascript that should execute on submit.
* @author Daniel Plücken <daniel@debakel.net>
* Sets the target script of the data; The "action"-attribute.
* @author Daniel Plücken <daniel@debakel.net>
* Sets the target frame where the target script should appear; The
* @author Daniel Plücken <daniel@debakel.net>
* Sets the method, how the data should be send; POST or GET.
* @author Daniel Plücken <daniel@debakel.net>
* Sets the javascript error message that appears if user information is
* @author Daniel Plücken <daniel@debakel.net>
* Overides the body of the form with the given custom string.
* @author Daniel Plücken <daniel@debakel.net>
* Stores that the HTML-elements should not format by "\r\n" in the source.
* @author Daniel Plücken <daniel@debakel.net>
* Adds text into the form.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $where Possible values are:
* Adds references of form-items to this object.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $requireJSOutput
* @return mixed The reference to the added form item.
echo "You add an empty variable to a form in the script "
. $debug_arr[$last_debug_index]["file"]. " at line "
. $debug_arr[$last_debug_index]["line"]. "!<br />";
echo "You add not a valid form item to a form in the script "
. $debug_arr[$last_debug_index]["file"]. " at line "
. $debug_arr[$last_debug_index]["line"]. "!<br />";
$item->parentform = &$this;
if ( !empty( $requireJSOutput ) )
is_a( $item, "HTMLFileInput" )
* Adds hidden-form-items to this object.
* @author Daniel Plücken <daniel@debakel.net>
* @param string|object $name
is_a( $name, "HTMLHiddenInput" )
$_REQUEST[$name] == $_POST[$name]
|| $_REQUEST[$name] == $_GET[$name]
$value = $_REQUEST[$name];
// Add a new item if there is not an item
// with the same name as the given one.
* Adds dummy-form-item to this object. It doesn't apear on the website.
* It is only to inform the form about a custum generatet input field, for
* example to add the FCKeditor to the form.
* @author Daniel Plücken <daniel@debakel.net>
* @param string|object $name
* Removes the hidden item with the given name.
* @author Daniel Plücken <daniel@debakel.net>
* Changes the value of the hidden form item with the given namen.
* @author Daniel Plücken <daniel@debakel.net
* Disables all formitems.
* @author Daniel Plücken <daniel@debakel.net>
* Disables all formitems. This function is an alias for the function
* @author Daniel Plücken <daniel@debakel.net>
* Disables all formitems. This function is an alias for the function
* @author Daniel Plücken <daniel@debakel.net>
* Returns the count of items of this form.
* @author Daniel Plücken <daniel@debakel.net>
* Returns a javascript to validate the input of the form.
* @author Daniel Plücken <daniel@debakel.net>
$out = "\r\n <script type=\"text/javascript\">\r\n";
$out .= " function checkData()\r\n";
$out .= " errMSG = \"\";\r\n";
# Verification of fields that have to be filled
$out .= " if( !". $tmp. " )\r\n";
$out .= " return false;\r\n\r\n";
# Javascript to probe the fields that have to be filled
$out .= " if( ". $tmp. " )\r\n";
$out .= " if( errMSG == \"\" )\r\n";
$out .= " return true;\r\n";
$out .= " alert( unescape( '". $this->js_err_msg. "' + errMSG ) );\r\n";
$out .= " return false;\r\n";
$out .= " </script>\r\n\r\n";
* Generates the sourcecode to build this object and returns it.
* @author Daniel Plücken <daniel@debakel.net>
$out .= "\x24form->setLayoutTable( \x24table );\r\n";
$out .= "\x24form->addFormItem( \x24input[". $i. "], "
$out .= "\x24form->addFormItem( \x24input[". $i. "] );\r\n";
return $out; "\x24form->setLayoutTable( \x24table );\r\n";
* Generates the sourcecode to build this object and returns it.
* @author Daniel Plücken <daniel@debakel.net>
$out .= $this->formItems[$i]->getPHPSource(). "\r\n\r\n";
$out .= "\x24formname = \"". $this->getName(). "\";\r\n";
$out .= !empty( $this->method )
? "\x24method = \"". $this->getMethod(). "\";\r\n"
$out .= "\x24form = new HTMLForm(\r\n"
. " \x24onSubmitOrder,\r\n"
* Returns a generated string based on the Attributes of this HTML-Object.
* @author Daniel Plücken <daniel@debakel.net>
* @param HTMLTable $obj_ref A reference of a table by dint of the form
* should be formatted. The form items will be
* placed in the table where the string "[item]"
* @param boolean $php_code Is this parameter true, the form will be
* returned as the source-php-code of this
function get( $obj_ref = "", $php_code = false )
} // End of class HTMLForm
|