Thura Aung
Thura Aung

Reputation: 93

Cakephp Form Helper Input's label to place outside of the div

I've googled and only found before after answer to get this done but that does not fit my problem. I want to move default label element outside of the div.

<?php echo $this->Form->input('name', array( 'before' => $this->Form->label('Subject:'), 'class' => 'form-control', 'div' => 'col-md-9 col-sm-9 col-xs-12')); ?>

Output is

<div class="col-md-9 col-sm-9 col-xs-12 required">
  <label for="StaffSubject:">Subject:</label>
  <input name="data[Staff][name]" class="form-control" maxlength="255" type="text" id="StaffName" required="required">
</div>

But I want this output instead

<label for="StaffSubject:">Subject:</label>
<div class="col-md-9 col-sm-9 col-xs-12 required">
  <input name="data[Staff][name]" class="form-control" maxlength="255" type="text" id="StaffName" required="required">
</div>

Upvotes: 1

Views: 756

Answers (2)

Inigo Flores
Inigo Flores

Reputation: 4469

This should work:

<?php echo $this->Form->input('name', array(
    'label'=>'Subject',
    'class' => 'form-control',
    'wrapInput' => 'col-md-9 col-sm-9 col-xs-12',
)); ?>

Upvotes: 1

Ch0c4
Ch0c4

Reputation: 26

the best solution for that is to remove the label from your input and added before your input

<?php echo $this->Form->label('Subject:');
      echo $this->Form->input('name', array( 
          'label' => false, 
          'class' => 'form-control', 
          'div' => 'col-md-9 col-sm-9 col-xs-12'
      )); ?>

Upvotes: 1

Related Questions