=====Advanced Form Open===== //Installed as a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12.// >>See also: ~-WikkaCore ~-GenerateUniqueId ~-Mod015fFilesAction ~-EmailpasswordActionInfo ~-AdvancedReferrersHandler ~-GrabCodeHandler >>The [[Docs:WikkaCore Wikka core]] has a ##""FormOpen()""## method that creates the opening tag for a form. However, it has a number of limitations, such as no way to specify an ##id## and/or ##class## attribute, and not supporting ##enctype## needed for a file upload form. This leads to ugly workarounds and inconsistent (and sometimes invalid) code. The following replacement for ##""FormOpen()""## addresses these issues and makes sure the generated code is valid XHTML. It uses a number of new supporting methods that will be more generally useful as well. ====New ##""FormOpen()""## method==== The folowing code should replace the ##""FormOpen()""## method in ##wikka.php## (at line 694 in the 1.1.6.0. release version ~-''modified to make use of the new ##[[GenerateUniqueId makeId()]]## method'' ~-''modified to use lowercase form method values (required by XHTML)'' %%(php;694) /** * Build an opening form tag with specified or generated attributes. * * This method builds an opening form tag, taking care that the result is valid XHTML * no matter where the parameters come from: invalid parameters are ignored and defaults used. * This enables this method to be used with user-provided parameter values. * * The form will always have the required action attribute and an id attribute to provide * a 'hook' for styling and scripting. This method tries its best to ensure the id attribute * is unique, among other things by adding a 'form_' prefix to make it different from ids for * other elements. * For a file upload form ($file=TRUE) the appropriate method and enctype attributes are generated. * * When rewriting is not active, a hidden field is attached as well to pass on the page name. * NOTE: is this really needed?? * * @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} * @copyright Copyright © 2005, Marjolein Katsma * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * * @access public * @uses makeId() * @uses ID_LENGTH * @uses existsHandler() * @uses existsPage() * @uses Href() * @uses MiniHref() * * @param string $method optional: "method" which consists of handler and possibly a query string * to be used as part of action attribute * @param string $tag optional: page name to be used for action attribute; * if not specified, the current page will be used * @param string $formMethod optional: method attribute; must be POST (default) or GET; * anything but POST is ignored and considered as GET; * always converted to lowercase * @param string $id optional: id attribute * @param string $class optional: class attribute * @param boolean $file optional: specifies whether there will be a file upload field; * default: FALSE; if TRUE sets method attribute to POST and generates * appropriate enctype attribute * @return string opening form tag and hidden input field when not rewriting. */ function FormOpen($method='',$tag='',$formMethod='post',$id='',$class='',$file=FALSE) { $attrMethod = ''; # no method for HTML default 'get' $attrClass = ''; $attrEnctype = ''; # default no enctype -> HTML default application/x-www-form-urlencoded $hiddenval = ''; // validations $validMethod = $this->existsHandler($method); $validPage = $this->existsPage($tag); // derivations (MiniHref supplies current page name if none specified) $page = ($validPage) ? $tag : ''; $method = ($validMethod) ? $method : ''; // form action (action is a required attribute!) $attrAction = ' action="'.$this->Href($method, $page).'"'; // form method (ignore anything but post) and enctype if (TRUE === $file) { $attrMethod = ' method="post"'; # required for file upload $attrEnctype = ' enctype="multipart/form-data"'; # required for file upload } elseif (preg_match('/^post$/i',$formMethod)) # ignore case... { $attrMethod = ' method="post"'; # ...but generate lowercase } // form id if ('' == $id) # if no id given, generate one based on other parameters { $id = substr(md5($method.$tag.$formMethod.$class),0,ID_LENGTH); } $attrId = ' id="'.$this->makeId('form',$id).'"'; # make sure we have a unique id // form class if ('' != $class) { $attrClass = ' class="'.$class.'"'; } // build HTML fragment $result = '