Detailed application of xml in the joomla form

Source: Internet
Author: User
Xml is widely used in joomla. from installation file configuration to templates, modules, components, and plug-ins, all applications are used in fixed formats, here we mainly talk about the application of xml in creating forms. the role of forms is self-evident. there are forms in the module configuration and forms in the component. the parameter settings in the configuration here are the forms generated by xml, which is much easier than directly creating forms, before editing the document form, let's take a look at the type of the form element. joomla provides multiple forms element styles.
The code is as follows:
// Generate the calendar time
// Obtain the unit List
// List of other component units
// Editor selection list
// File list html indicates that the display extension is html
// Folder list
// Hide the domain


// Password
// Single answer

// Unit selection
// Horizontal line
// SQL Generation list
// Text box
// No style for text fields
// The text field has a style
// Generate the time zone list

Some generated elements are provided above. but how to use them? First, we create a form. xml file in the models folder of the component.
The code is as follows:

Here there is only one hidden element. In fact, we can create more elements, that is, the above generated element types. of course, we can also customize them. here, addpath is the custom element type, the location is in the created elements folder. the above is built-in. the following types are defined here.
The code is as follows:
// Custom control
// Convert an array to a list without writing a subscript starting from 0
// Whether to generate a single choice
// Upload control
// Check the array
// Unlimited classification. Note that the parent class of section is 0.

Using metadata, you can access view.html. php in your view folder under the viewsfolder by adding the following statement:
The code is as follows:
$ Form = new JParameter ('', JPATH_COMPONENT.DS. 'models'. DS. 'form. XML ');
$ Form-> set ('M1 ', 'default ');
$ Html = $ form-> render ('Details', 'html'); // details is an array of element names
$ This-> assignRef ('html', $ html );

The second sentence above is a value assignment. assigning values to hidden fields is equivalent to the value in editing. The third sentence is to output the form html to the template. details is the array name of element names, the generated m1 name is details [m1], followed by form. php calls are as follows:
The code is as follows:

This form is generated. this method is easier to modify the style or content than to directly write the form element. you only need to modify the xml file. in joomla2.5, basically, this method is implemented in this way, but the changes are relatively large, and the syntax of xml files is quite different. xml allows you to call the form elements in other components.

These types of form elements can be used in template configuration parameters and module parameters. in particular, you can extend the style of form elements by yourself. you can define other style types completely, I have defined several commonly used styles that are not provided with built-in functions, such as array conversion list, array conversion check, and unlimited classification. the type here is actually the JElement class of the api. for the source files, see libraries \ joomla \ html \ parameter \ element, here, how to write custom form elements? here is an example or reference to the source file. the file name is M. php, the type is custom. call method
The code is as follows:
// Custom display
Defined ('_ JEXEC') or die ('restricted access ');

Class JElementCustom extends JElement {
Var $ _ name = 'custom ';
Function fetchElement ($ name, $ value, & $ node, $ control_name ){
$ Html = < Custom
Return $ html;

Well, I will not talk about it more. In fact, this is just a method to create a form. if you don't like it, you can use the form element. but since joomla provides these, why don't we use them?
Download custom element: elements_jb51.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.