Basically have a fixed format to use, in this not much to say, this is mainly about the application of XML in creating forms. The function of the form is self-evident, in the module configuration inside has the form, the component inside also has the form, here's configuration inside the parameter setting is the XML generation form, relative to through directly constructs the form to be convenient many, Here, by editing the use of the article form, before using, let's take a look at the types of form elements that Joomla offers to generate a variety of form element styles.
Copy Code code as follows:
<param name= "created" type= "Calendar" label= "Create Time" description= "time display"/>//Generate calendar Time
<param name= "catid" type= "category" default= "2" label= "category" description= "article classification list"/>//Get cell list
<param name= "catid" type= "category" Section= "com_weblinks" default= "0" label= "category" description= "other component categories"/> List of other component units
<param name= ' M1 ' type= ' Editors ' label= ' edit '/>//editor selection list
<param name= ' M1 ' type= ' filelist ' label= ' edit ' directory= '/images ' hide_default= ' 1 ' filter= ' html '/>//File list HTML representation shows the extension as HTML
<param name= ' M1 ' type= ' folderlist ' label= ' edit ' directory= '/images ' hide_default= ' 1 "filter=" "/>//Folder List
<param name= ' M1 ' type= ' Hidden '/>//hidden fields
<param name= "file_name" type= ImageList "directory="/images/stories "filter=" "hide_default=" 1 "label=" "Menu Image" description= "Picture List List"/>
<param name= "list" type= "list" label= "select list" description= "select list" >
<option value= "" > Not categorized </option>
<option value= "0" > China </option>
<option value= "1" > USA </option>
</param>
<param name= ' M1 ' type= ' password ' label= ' test ' size= '/>//password
<param name= "Cache" type= "Radio" default= "0" label= "single Select" description= "radio button" >//Radio
<option value= "0" >No</option>
<option value= "1" >Yes</option>
</param>
<param name= "SectionID" type= "section" default= "0" label= "SELECT unit" description= "unit"/>//Unit selection
<param type= "spacer"/>/horizontal Line
<param name= ' M1 ' type= ' SQL ' label= ' test ' query= ' select Id,title from #__categories ' key_field= ' id ' value_field= ' title ' />//sql Build List
<param name= "Robots" type= "text" size= "default=" "label=" text box "description=" text box text "/>//text box
<param name= "keywords" type= "textarea" rows= "5" cols= "label=" text field "description=" text field textarea "/>//Text field no style
<param name= "keywords" type= "editor" rows= "5" cols= "label=" text field "description=" text field textarea "/>//text field has style
<param name= ' M1 ' type= ' timezones ' label= ' Test ' default= ' 8 '/>//Generate time zone list
The top is some of the generated elements provided, but how to use it, we first set up a form.xml in the component's Models folder
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<form>
<name> Forms Test </name>
<fieldset name= ' Details '/>
<params group= "html" addpath= "/administrator/components/com_category/elements" >
<param name= ' M1 ' type= ' Hidden '/>
</params>
</form>
There's only one hidden element. In fact, we can create more elements, that is, the top of those generated element types, of course, can also be customized, here is the addpath of the custom element type, the location is in the elements folder, the above is built, the author here defines the following types
Copy Code code as follows:
<param name= ' Custom ' type= ' Customize ' label= ' >//Custom controls
<param name= ' arr ' type= ' arr ' label= ' array ' arr= ' array (1=> ' China ',2=> ' USA ') "/>//array to list do not write subscript starting from 0
<param name= ' radios ' type= ' radios ' label= ' whether single selection ' >//Generate whether single
<param name= ' arr ' type= ' upload ' label= ' array ' size= '/>//upload Control
<param name= ' arr ' type= ' checkbox ' label= ' array ' arr= ' array (' 1 ' => ' China ', ' 2 ' => ' Us ') "/>//array check
<param name= ' type ' type= ' type ' label= ' wireless classification '/>//Infinite categories Note Add section parent class to 0
Using the method as above, the custom file for the element is provided in the download. Then we add the following statement to the view.html.php in your view folder below the Views folder
Copy Code code as follows:
$form = new Jparameter (', jpath_component. DS. ' Models '. DS. ' Form.xml ');
$form->set (' M1 ', ' default value ');
$html = $form->render (' Details ', ' HTML '); Details are element array group
$this->assignref (' HTML ', $html);
The second sentence above is the assignment, the hidden field assignment, equivalent to the editor, the 34th sentence is the form of HTML output to the template, details is the name of the array of element names, the generated M1 name is DETAILS[M1], and then is form.php call the following
Copy Code code as follows:
<form action= "index.php" method= "post" name= "Adminform" >
<fieldset class= "Adminform" ><legend> details </legend>
<?php
Echo $this->html;
?>
<?php echo jhtml::_ (' Form.token ');?>
</fieldset>
</form>
Such a form is generated, relative to the direct write form elements, this method is easier to modify the style or content, modify only need to change the XML file, in the joomla2.5 version, basically is implemented in this way, but the change is relatively large, XML file writing is very different, The form elements within other components can be invoked through XML.
These types of form elements are configured in the template parameters, module parameters are available, especially if you can extend the style of the form elements, you can define other style types, the author defines a few of the more commonly used but not provided in the built-in, such as array conversion list, array conversion check, Infinite classification and other styles. The type here is actually the API Jelement class, where the source file can refer to Libraries\joomla\html\parameter\element, Here to customize the form elements how to write it here for an example or reference to the source file to understand that the filename custom.php, the type is custom, call method <param name= ' custom ' type= ' Customize ' label= ' >
Copy Code code as follows:
<?php
Custom display
//
Defined (' _jexec ') or Die (' restricted access ');
Class Jelementcustom extends jelement{
var $_name = ' Custom ';
function Fetchelement ($name, $value, & $node, $control _name) {
$html =<<<eof
Custom
EOF;
return $html;
}
}
Well, not much to say, in fact, this is just a way to create a form, if you do not like, you can use to write form elements, but since Joomla provides these why do we not?
Download custom elements: Elements_jb51.rar