How to Create Form Labels

The Form::label() method can be used to create form labels.

The first parameter

The first parameter is the label's for attribute. With the second parameter NULL (the default) this argument will also be used as the label's text with all non-word characters turned into spaces and title cased.

  <?php echo Form::label('email_address') ?>
  <?php echo Form::input('email', NULL, array('id' => 'email_address')) ?>

Results:

  <label for="email_address">Email Address</label>
  <input name="email" type="text" id="email_address" />

Note: Since DOM IDs are unique and used for the label's for attribute you should provide your input with an id attribute as well.

The second parameter

The second parameter is the label's text

  echo Form::label('firstname', 'First Name');
  <label for="firstname">First Name</label>

The third parameter

The third parameter accepts an array of attributes

  echo Form::label('lastname', 'Last Name', array('class'=>'error'));
  <label for="lastname" class="error">Field Name</label>
how_to_create_form_labels.txt · Last modified: 2010/09/04 06:38 by joelpittet