Xml application in joomla forms

Source: Internet
Author: User
Xml is widely used in joomla, from installation file configuration to templates, modules, components, and plug-ins.

Xml is widely used in joomla, from installation file configuration to templates, modules, components, and plug-ins.

There are basically fixed formats for use. Here we will not 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


Unclassified
China
USA

// Password
// Single answer
No
Yes

// 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
EOF;
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 elements:

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: info-contact@alibabacloud.com 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.