Headers

Headers – how to customize labels

Introduction

A label is a description text that will be displayed near the element. Some renderers can handle multiple labels for the element. Placeholders used by these renderers are different in naming convention. Nevermind, HTML_QuickForm_advmultiselect used only one standard coding that is equivalent to the QuickForm default renderer.

As {label_2} is the placeholder for the second label (unselected list), {label_3} is the placeholder for the third label (selected list), in the hash setting. See HTML_Quickform::setLabel method.

The first label is always for the advmultiselect element group itself. Its name depend of the QuickForm renderer used. See examples that follow to notice the difference.

Naming with QuickForm Default Renderer

<?php
require_once 'HTML/QuickForm.php';
require_once 
'HTML/QuickForm/advmultiselect.php';

$template =
'<tr>
    <td align="right" valign="top">
        <b>{label}</b>
    </td>
    <td valign="top" align="left">
        {element}
        <!-- BEGIN error --><br/><font color="red">{error}</font><br/><!-- END error -->
    </td>
</tr>'
;

// Create the form, and add a header to it.
$form = new HTML_QuickForm('qfamsLabels');
$form->addElement('header'null'QuickForm Labels Example: default renderer');

$cars = array(
    
'dodge'     =>  'Dodge',
    
'chevy'     =>  'Chevy',
    
'bmw'       =>  'BMW',
    
'audi'      =>  'Audi',
    
'porsche'   =>  'Porsche',
    
'kia'       =>  'Kia',
    
'subaru'    =>  'Subaru',
    
'mazda'     =>  'Mazda',
    
'isuzu'     =>  'Isuzu',
);

$labels = array('Cars:''Models''Your selection');

// Do the magic! Just pass your label to the element as an array!
$form->addElement('advmultiselect''cars'$labels$cars);

// customize the element template
$renderer =&amp$form->defaultRenderer();
$renderer->setElementTemplate($template);

// output the form
$form->display();
?>
Line 8 :

The first label with default renderer, is always named {label}.

Line 32 :

In this example, its value will be Cars:

Naming with QuickForm ITDynamic Renderer

<?php
require_once 'HTML/Template/Sigma.php';
require_once 
'HTML/QuickForm.php';
require_once 
'HTML/QuickForm/Renderer/ITDynamic.php';
require_once 
'HTML/QuickForm/advmultiselect.php';

$template '
<form {qf_attributes}>
<table class="maintable">

<!-- BEGIN qf_hidden_block -->
<div style="display: none;">
  <!-- BEGIN qf_hidden_loop -->{qf_hidden}<!-- END qf_hidden_loop -->
</div>
<!-- END qf_hidden_block -->

<!-- BEGIN qf_main_loop -->

  <!-- BEGIN qf_header -->
  <tr><th class="maintable" colspan="2">{qf_header}</th></tr>
  <!-- END qf_header -->

  <!-- BEGIN qf_element -->
  <tr>
    <td align="right" width="30%"><span class="qfLabel">{qf_label}&amp;nbsp;</span></td>
    <td>{qf_element}
      <!-- BEGIN qf_element_error --><br /><span style="color: #FF0000;">{qf_error}</span><!-- END qf_element_error -->
    </td>
  </tr>
  <!-- END qf_element -->

<!-- END qf_main_loop -->
</table>
</form>
'
;

// Create the form, and add a header to it.
$form = new HTML_QuickForm('qfamsLabels');
$form->addElement('header'null'QuickForm Labels Example: itdynamic renderer');

$cars = array(
    
'dodge'     =>  'Dodge',
    
'chevy'     =>  'Chevy',
    
'bmw'       =>  'BMW',
    
'audi'      =>  'Audi',
    
'porsche'   =>  'Porsche',
    
'kia'       =>  'Kia',
    
'subaru'    =>  'Subaru',
    
'mazda'     =>  'Mazda',
    
'isuzu'     =>  'Isuzu',
);

$labels = array('Cars:''Models''Your selection');

// Do the magic! Just pass your label to the element as an array!
$form->addElement('advmultiselect''cars'$labels$cars);

// set the form template
$tpl = new HTML_Template_Sigma('.');
$tpl->setTemplate($template);

$renderer = new HTML_QuickForm_Renderer_ITDynamic($tpl);

$form->accept($renderer);

// output the form
$tpl->show();
?>
Line 25 :

The first label with ITDynamic renderer, is always named {qf_label}.

Line 53 :

In this example, its value is still Cars:

In practice

Lets review in details how to set the appearance of headers in one of examples included in the package.

After the labels are set:

<?php
$ams
->setLabel(array('Fruit:''Available''Selected'));
?>

Have a special look on the advmultiselect template element. Here is it:

<?php
$template 
'
<table{class}>
<!-- BEGIN label_2 --><tr><th align="center">{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th align="center">{label_3}</th></tr><!-- END label_3 -->
<tr>
  <td>{unselected}</td>
  <td>{selected}</td>
</tr>
<tr>
  <td align="center">{add}</td>
  <td align="center">{remove}</td>
</tr>
</table>'
;
?>
Line 4 :

Header for the unselected list (named Available) is center aligned in bold with the TH tag.

Line 5 :

Header for the selected list (named Selected), is also center aligned in bold with another TH tag.

To give only a header to the selection list, either you set values as:

<?php
$ams
->setLabel(array('Fruit:'null'Your selection'));
?>

or you remove line beginning by <!-- BEGIN label_2 --> into the advmultiselect template element.

Advanced features (Previous) how to customize action buttons (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.