Note: You are currently viewing documentation for Moodle 3.7. Up-to-date documentation for the latest stable version of Moodle may be available here: Frank Ralf/Semantic HTML5.

User:Frank Ralf/Semantic HTML5: Difference between revisions

From MoodleDocs
Line 6: Line 6:


<code php>
<code php>
$mform->addElement('header', 'checkboxes', get_string('checkboxtest', 'block_simpleblock'));
$mform->addElement('header', 'checkboxes', 'checkboxtest');
  $mform->addElement(
$mform->addElement(
    'checkbox',
  'checkbox',
    'TEACHER',
  'TEACHER',
    'Mr. Smith',
  'Mr. Smith',
    'History',                       
  'History',                       
    array('class'=>'pe_teacher', 'id'=> 'SMITH')
  array('class'=>'pe_teacher', 'id'=> 'SMITH')
    );
  );


  $mform->addElement(
$mform->addElement(
    'checkbox',                 
  'checkbox',                 
    'teachers',   
  'teachers',   
    'Ms. Miller',
  'Ms. Miller',
    'Math',                         
  'Math',                         
    array('class'=>'pe_teacher', 'id'=> 'miller')  
  array('class'=>'pe_teacher', 'id'=> 'miller')  
    );
  );
</code>
</code>



Revision as of 20:09, 15 June 2009

formslib - checkboxes

Styling forms proves a bit difficult due to the way formslib.php renders the individual form items. Let's look at a simple example:

Example PHP

$mform->addElement('header', 'checkboxes', 'checkboxtest'); $mform->addElement(

 'checkbox',
 'TEACHER',
 'Mr. Smith',
 'History',                      
 array('class'=>'pe_teacher', 'id'=> 'SMITH')
 );

$mform->addElement(

 'checkbox',                 
 'teachers',  
 'Ms. Miller',
 'Math',                         
 array('class'=>'pe_teacher', 'id'=> 'miller') 
 );

Screenshots

That looks quite unsuspicious:

Formslib checkboxes.png

Let's add some CSS to see the details:

fieldset#checkboxes {background-color: yellow;} fieldset#checkboxes * {margin: 5px; padding: 5px;}

legend{background-color: lime;} div.fcontainer {background-color: blue;} div.fitem {background-color: red;} div.fitemtitle {background-color: silver;} label {background-color: aqua;} div.felement {background-color: teal;} span {background-color: orange;} input.pe_teacher {background-color: fuchsia; border: 3px dotted purple;}

Formslib checkboxes-colorful.png

And with some margings and padding added:

Formslib checkboxes colorful-with-margins.png


Output HTML

So let's have a closer look at the markup Moodle provides (only first form item shown):

<fieldset class="clearfix" id="checkboxes">

 <legend class="ftoggler">Checkbox Test</legend>

</fieldset>

See also

  • MDL-10505 (Add group name to rendered elements for better CSS control)
  • MDL-11134 (Help links in forms are outside the <label> - they will be ignored in JAWS forms mode)