Home >Backend Development >PHP Tutorial >Detailed explanation and sharing of the application of xml in joomla forms_PHP tutorial

Detailed explanation and sharing of the application of xml in joomla forms_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:17:55753browse

There is basically a fixed format for use. I won’t go into details here. Here I 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 there are also forms in the components. In the configuration here The parameter setting is the form generated by xml. Compared with directly creating the form, it is much more convenient. Here is the process of using the edit article form. Before using it, let's first understand the types of form elements. Joomla provides a variety of generated forms. Form element style.

Copy code The code is as follows:

//Generate calendar time
//Get unit list
//Editor selection list
//The file list html indicates that the display extension is html
//Folder list





//Password
//Radio choice



//Unit selection
//Horizontal line
//SQL generated list
//Text box
//Textarea has no style
//Text area has style
//Generate time zone list

The above are some generated elements provided, but how to use it? We first create a form.xml and copy the code in the models folder of the component
> The code is as follows:


form Test


< param name='m1' type='Hidden'/>



There is only one hidden element here but we can create more The elements are the generated element types above. Of course, they can also be customized. The addpath here is the custom element type. The location is in the elements folder of the component. The above ones are built-in. The author defines the following types here

Copy code The code is as follows:

//Custom control
//Convert the array into a list without writing the subscript starting from 0
//Generate whether it is a radio choice
//Array check
//Infinite classification, please note that the parent class of section is 0

The usage method is as above, the custom file of the element is provided in the download. Then we add the following statement to view.html.php in your view folder under the views folder
Copy code The code is as follows:

$form = new JParameter('',JPATH_COMPONENT.DS.'models'.DS.'form.xml');
$form->set('m1','default value');
$html=$form->render('details', 'html'); //details is an array of element names
$this->assignRef('html',$html);

The second sentence above is assignment. Assigning a value to a hidden field is equivalent to taking a value in editing. The third and fourth sentences are The form html is output to the template, details is the name of the element name array, the name of the generated m1 is details[m1], and then form.php is called as follows
Copy code The code is as follows:


< legend>Details
echo $this->html;
?>




Such a form is generated. This method is easier to modify than writing form elements directly. To modify the style or content, you only need to change the xml file. In the joomla2.5 version, it is basically implemented in this way, but the changes are relatively large. The way of writing xml files is very different. Other components can be called through xml. The form elements inside.

These types of form elements can be used in the template configuration parameters and module parameters. In particular, you can extend the style of the form elements by yourself. You can completely define other style types. The author defines There are several commonly used ones that are 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 JElement class of the API. The source file inside can refer to librariesjoomlahtmlparameterelement. Here are the custom form elements. How to write it? You can understand by giving an example here or referring to the source file. The file name is custom.php, the type is custom, and the calling method
Copy code 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=<<Customized
EOF;
return $html;
}
}

Okay, I won’t go into details. In fact, this is just a way to create a form. If you don’t like it, you can definitely use form elements, but since joomla provides these, why don’t we use them?
Download custom elements: elements_jb51.rar

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325610.htmlTechArticleIt basically has a fixed format when used. I won’t go into details here. Here I mainly talk about the use of xml in creating forms. Application. The role of forms is self-evident. There are forms in the module configuration, and there are also forms in the components...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn