cvs: pear /HTML_QuickForm QuickForm.php

From: Date: Tue, 16 Oct 2001 13:25:28 +0000
Subject: cvs: pear /HTML_QuickForm QuickForm.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1035@lists.php.net to get a copy of this message
mansion Tue Oct 16 09:25:28 2001 EDT Modified files: /pear/HTML_QuickForm QuickForm.php Log: Added support for file uploads. This can be improved with error management, filename cleanup... To improve it, have a look at the moveUploadedFile method. Index: pear/HTML_QuickForm/QuickForm.php diff -u pear/HTML_QuickForm/QuickForm.php:1.2 pear/HTML_QuickForm/QuickForm.php:1.3 --- pear/HTML_QuickForm/QuickForm.php:1.2 Thu Sep 13 10:31:38 2001 +++ pear/HTML_QuickForm/QuickForm.php Tue Oct 16 09:25:27 2001 @@ -17,11 +17,9 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: QuickForm.php,v 1.2 2001/09/13 14:31:38 mansion Exp $ - +// $Id: QuickForm.php,v 1.3 2001/10/16 13:25:27 mansion Exp $ require_once("PEAR.php"); require_once("HTML/Common.php"); - /** * Create, validate and process HTML forms * @@ -30,9 +28,7 @@ * @version 1.0 * @since PHP 4.0.3pl1 */ - class HTML_QuickForm extends HTML_Common { - /** * Array containing the form fields * @since 1.0 @@ -40,7 +36,6 @@ * @access private */ var $_elements = array(); - /** * Array containing required field IDs * @since 1.0 @@ -72,7 +67,6 @@ * @access public */ var $_jsPostfix = "Please correct these fields."; - /** * Array of form values * @since 1.0 @@ -96,7 +90,6 @@ * @access public */ var $_submitFiles = array(); - /** * Value for maxfilesize hidden element if form contains file input * @since 1.0 @@ -111,7 +104,6 @@ * @access private */ var $_hidden = array(); - /** * Array containing the frozen fields * @since 1.0 @@ -127,7 +119,6 @@ * @access private */ var $_freezeAll = false; - /** * Array containing the form rules * @since 1.0 @@ -135,7 +126,6 @@ * @access private */ var $_rules = array(); - /** * Array containing the validation errors * @since 1.0 @@ -143,7 +133,6 @@ * @access private */ var $_errors = array(); - /** * Note for required fields in the form * @var string @@ -174,7 +163,6 @@ 'text' =>array('HTML_QuickForm/Elements/text.php','HTML_QuickForm_text'), 'textarea' =>array('HTML_QuickForm/Elements/textarea.php','HTML_QuickForm_textarea') ); - /** * Array of registered element types * @var array @@ -192,7 +180,6 @@ 'lettersonly' =>array('regex', '^[a-zA-Z]*$'), 'alphanumeric' =>array('regex', '^[a-zA-Z0-9]*$') ); - /** * Class constructor * @param string $formName Form's name. @@ -221,7 +208,6 @@ { return 1.0; } // end func apiVersion - /** * Registers a new element type * @@ -237,7 +223,6 @@ { $this->_registeredTypes[$typeName] = array($include, $className); } // end func registerElementType - /** * Registers a new validation rule * @@ -254,7 +239,6 @@ { $this->_registeredRules[$ruleName] = array($type, $data1, $data2); } // end func registerRule - /** * Returns true if element is in the form * @@ -299,7 +283,6 @@ } } } // end func loadDefaults - /** * Load form elements with submitted values * @@ -331,16 +314,14 @@ } else { $this->_elementValues[$elementList] = $this->_submitValues[$elementList]; } - - // Uploads management FIX ME - /* + $this->_submitFiles = $GLOBALS["HTTP_POST_FILES"]; for (reset($this->_submitFiles); $key = key($this->_submitFiles); next($this->_submitFiles)) { $value = pos($this->_submitFiles); $value = is_string($value) ? stripslashes($value) : $value; $this->_submitFiles[$key] = $value; $this->$key = $value; - }*/ + } } // end func loadValues /** @@ -352,7 +333,9 @@ */ function moveUploadedFile($element, $dest) { - $file = $this->_formFiles[$element]; + $file = $this->_submitFiles[$element]; + if ($dest != "" && substr($dest, -1) != "/") + $dest .= "/"; if (copy($file["tmp_name"], $dest . $file["name"])) { @unlink($file["tmp_name"]); return true; @@ -389,7 +372,6 @@ } return $elementObject; } // end func createElement - /** * Adds an element into the form * @@ -407,7 +389,7 @@ if ($elementType == "file" AND $this->_fileFlag == false) { $this->_fileFlag = true; $this->updateAttributes(array("method"=>"POST", "enctype"=>"multipart/form-data")); - $hiddenObject = new HTML_QuickForm_hidden("MAX_FILE_SIZE",$this->_maxFileSize,""); + $hiddenObject = &HTML_QuickForm::createElement('hidden', 'MAX_FILE_SIZE', $this->_maxFileSize, ''); $this->_hidden[] = $hiddenObject; } if (isset($this->_elementValues[$elementName]) && $elementType != "select") { @@ -479,7 +461,6 @@ { $this->_errors[$element] = $message; } // end func setElementError - /** * Adds a header in the form * @@ -493,7 +474,6 @@ { $this->_elements[] = array("header"=>$label); } // end func addHeader - /** * Adds a validation rule for the given field * @@ -522,7 +502,6 @@ $this->_rules[$element][] = array("type"=>$type, "format"=>$format, "message"=>$message, "validation"=>$validation); } // end func addRule - /** * Html Wrapper method for form elements (inputs...) * @@ -596,7 +575,6 @@ "$tabs</TABLE>"; return $html; } // end func _wrapForm - /** * Wrap footnote for required fields * @@ -617,7 +595,6 @@ "$tabs\t</TR>"; return $html; } // end func setCaption - /** * Builds the element as part of the form * @@ -671,7 +648,6 @@ $header = $element["header"]; return $this->_wrapHeader($header); } // end func _buildHeader - /** * Returns an HTML string of the hidden form elements * @@ -755,7 +731,6 @@ "$tabs</SCRIPT>"; return $html; } // end func _buildRules - /** * Returns whether or not the form element type is supported * @@ -769,7 +744,6 @@ { return in_array($type, array_keys($this->_registeredTypes)); } // end func isTypeRegistered - /** * Returns an array of registered element types * @@ -782,7 +756,6 @@ { return array_keys($this->_registeredTypes); } // end func getRegisteredTypes - /** * Returns whether or not the given rule is supported * @@ -796,7 +769,6 @@ { return in_array($name, array_keys($this->_registeredRules)); } // end func isRuleRegistered - /** * Returns an array of registered validation rules * @@ -809,7 +781,6 @@ { return array_keys($this->_registeredRules); } // end func getRegisteredRules - /** * Returns whether or not the form element is required * @@ -823,7 +794,6 @@ { return in_array($element, $this->_required); } // end func isElementRequired - /** * Returns whether or not the form element is frozen * @@ -837,7 +807,6 @@ { return in_array($element, $this->_frozen); } // end func isElementFrozen - /** * Performs the server side validation * @access public @@ -896,7 +865,6 @@ */ } } - if (count($this->_errors) > 0) { for (reset($files); $element=key($files); next($files)) { $file = pos($files); @@ -997,6 +965,5 @@ { print $this->toHtml(); } //end func display - } // end class HTML_QuickForm -?> \ No newline at end of file +?> \ No newline at end of file

« previous php.pear.cvs (#1035) next »