X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHTMLForm.php;h=cbd73a4610749972d182d82b210fec6b3b9b3313;hb=6cc7c3e09f2f22a9eb7a54f9bfe5edfa90c19316;hp=04d553f91ba5aabc4a4acc22df1c4f69376f8191;hpb=b6d74c6de1f15a81e10886fc5f8240f0306d8c1c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index 04d553f91b..cbd73a4610 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -1,89 +1,1550 @@ $info, + * where $info is an Associative Array with any of the following: + * + * 'class' -- the subclass of HTMLFormField that will be used + * to create the object. *NOT* the CSS class! + * 'type' -- roughly translates into the \n"; + function suppressReset( $suppressReset = true ) { + $this->mShowReset = !$suppressReset; } - /* - * @access private - * @param string $varname Name of the textbox. - * @param string $value Optional value (default empty) - * @param integer $size Optional size of the textbox (default 20) + /** + * Overload this if you want to apply special filtration routines + * to the form as a whole, after it's submitted but before it's + * processed. + * @param $data + * @return unknown_type */ - function textbox( $varname, $value='', $size=20 ) { - $value = isset( $GLOBALS[$varname] ) ? $GLOBALS[$varname] : $value; - return "
\n"; + function filterDataForSubmit( $data ) { + return $data; } +} + +/** + * The parent class to generate form fields. Any field type should + * be a subclass of this. + */ +abstract class HTMLFormField { + + protected $mValidationCallback; + protected $mFilterCallback; + protected $mName; + public $mParams; + protected $mLabel; # String label. Set on construction + protected $mID; + protected $mClass = ''; + protected $mDefault; + public $mParent; + + /** + * This function must be implemented to return the HTML to generate + * the input object itself. It should not implement the surrounding + * table cells/rows, or labels/help messages. + * @param $value String the value to set the input to; eg a default + * text for a text input. + * @return String valid HTML. + */ + abstract function getInputHTML( $value ); - /* - * @access private - * @param string $varname Name of the radiobox. - * @param array $fields Various fields. + /** + * Override this function to add specific validation checks on the + * field input. Don't forget to call parent::validate() to ensure + * that the user-defined callback mValidationCallback is still run + * @param $value String the value the field was submitted with + * @param $alldata Array the data collected from the form + * @return Mixed Bool true on success, or String error to display. */ - function radiobox( $varname, $fields ) { - foreach ( $fields as $value => $checked ) { - $s .= "
\n"; + function validate( $value, $alldata ) { + if ( isset( $this->mValidationCallback ) ) { + return call_user_func( $this->mValidationCallback, $value, $alldata ); + } + + return true; + } + + function filter( $value, $alldata ) { + if ( isset( $this->mFilterCallback ) ) { + $value = call_user_func( $this->mFilterCallback, $value, $alldata ); } - return $this->fieldset( $this->mName.'-'.$varname, $s ); + + return $value; } - - /* - * @access private - * @param string $varname Name of the textareabox. - * @param string $value Optional value (default empty) - * @param integer $size Optional size of the textarea (default 20) + + /** + * Should this field have a label, or is there no input element with the + * appropriate id for the label to point to? + * + * @return bool True to output a label, false to suppress + */ + protected function needsLabel() { + return true; + } + + /** + * Get the value that this input has been set to from a posted form, + * or the input's default value if it has not been set. + * @param $request WebRequest + * @return String the value */ - function textareabox ( $varname, $value='', $size=20 ) { - $value = isset( $GLOBALS[$varname] ) ? $GLOBALS[$varname] : $value; - return '