xml in joomla form application details sharing

  • 2020-05-19 04:22:14
  • OfStack

To use basic has a fixed format, in the not much said, here is mainly about xml application to create a form. The form the role of self-evident, there is a form in the module configuration, components inside the form, the configuration parameter is set inside here is xml generated form, relative to the through direct built form, convenient process through the use of editing articles form here, before using, we first to get to know one form element types, joomla provides generated a variety of style of form elements.
 
<param name="created" type="calendar" label=" Creation time " description=" Time to show " /> // Generate calendar time  
<param name="catid" type="category" default="2" label="Category" description=" Article classification list " /> // Get a list of cells  
<param name="catid" type="category" section="com_weblinks" default="0" label="Category" description=" Classification of other components " /> // List of other component units  
<param name='m1' type='editors' label=' The editor ' /> // The editor selects the list  
<param name='m1' type='filelist' label=' The editor ' directory='/images' hide_default="1" filter="html"/> // File list  html Represents the display extension name html 
<param name='m1' type='Folderlist' label=' The editor ' directory='/images' hide_default="1" filter=""/> // Folder list  
<param name='m1' type='Hidden'/> // Hidden field  
<param name="file_name" type="imagelist" directory="/images/stories" filter="" hide_default="1" label="Menu Image" description=" Picture list " /> 
<param name="list" type="list" label="select The list of " description="select  The list of "> 
<option value=""> unclassified </option> 
<option value="0"> China </option> 
<option value="1"> The United States </option> 
</param> 
<param name='m1' type='password' label=' test ' size='20'/> // password  
<param name="cache" type="radio" default="0" label=" The radio " description=" The radio button "> // The radio  
<option value="0">No</option> 
<option value="1">Yes</option> 
</param> 
<param name="sectionid" type="section" default="0" label=" Select the unit " description=" unit " /> // Unit selection  
<param type="spacer"/> // A horizontal line  
<param name='m1' type='sql' label=' test ' query="select id,title from #__categories" key_field='id' value_field='title' /> //SQL Generate a list of  
<param name="robots" type="text" size="20" default="10" label=" The text box " description=" The text box text" /> // The text box  
<param name="keywords" type="textarea" rows="5" cols="90" label=" Text field " description=" Text field  textarea" /> // The text field has no style  
<param name="keywords" type="editor" rows="5" cols="90" label=" Text field " description=" Text field  textarea" /> // Text fields have styles  
<param name='m1' type='Timezones' label=' test ' default='8' /> // Generate a list of time zones  

Above are some of the generated elements provided, but how to use them, we first create an form.xml, in the component's models folder
 
<?xml version="1.0" encoding="utf-8"?> 
<form> 
<name> Form the test  </name> 
<fieldset name='details'/> 
<params group="html" addpath="/administrator/components/com_category/elements"> 
<param name='m1' type='Hidden'/> 
</params> 
</form> 

There is only one hidden element and we can actually create more elements, which are the generated element types on the top, and of course we can also customize, addpath here is the custom element type, the location is in the elements folder, the top is built-in, the author defines the following types here
 
<param name='custom' type='custom' label=' The custom '> // Custom control  
<param name='arr' type='arr' label=' An array of ' arr="array(1=>' China ',2=>' The United States ')"/>// The array is converted to a list   I don't write subscripts from 0 start  
<param name='radios' type='radios' label=' Whether or not the radio '> // Generate whether to single  
<param name='arr' type='upload' label=' An array of ' size='20'/>// File upload  
<param name='arr' type='checkbox' label=' An array of ' arr="array('1'=>' China ','2'=>' The United States ')"/>// An array of check  
<param name='type' type='type' label=' Classification of wireless ' />// Infinite classification   Pay attention to add section The parent class for 0 

Use the method 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 under the views folder
 
$form = new JParameter('',JPATH_COMPONENT.DS.'models'.DS.'form.xml'); 
$form->set('m1',' The default value '); 
$html=$form->render('details', 'html'); //details It's an array of element names  
$this->assignRef('html',$html); 

The second sentence above is the assignment, which is equivalent to editing the value inside. The thirty-fourth sentence is the output of form html to the template. details is the array name of element names, and the name of m1 generated is details[m1]
 
<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> 

This one form is generated, relative to the written form elements directly, this method is easier to modify the style or content, modify, you just need to change xml files in joomla2. 5 version, basically all is by this way, but the change is bigger, xml files written in very different, through xml is can call other components inside the form elements.

Form elements of these types in the template configuration parameters, module parameters can be used, especially can expand the form elements of style, you can define the type of the other styles, the author defines the comparison of several commonly used but provides no built-in, such as an array of conversion list, array transformation check, unlimited categories such as style. Here is in fact the type api JElement class, the inside of the source files can be reference libraries \ joomla \ html \ parameter \ element, how do you write custom form elements here here for example or reference source The file is clear, the file name is custom.php, the type is custom, call the method < param name='custom' type='custom' label=' custom '/ >
 
<?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 
 The custom  
EOF; 
return $html; 
} 
} 

Okay, so I won't go into that, but it's really just a way of creating a form, and if you don't like it, you can use the write form element, but if joomla provides that, why don't we use it?
Download the custom element: elements_jb51.rar

Related articles: