CakePHP: $form->input('checkbox');
Asked Answered
C

3

6

with config div => false

$form->input('checkbox');

print

<input type="checkbox" value="1" ....>
<label>checkbox</label>

but i want it reverse order

<label>checkbox</label>
<input type="checkbox" value="1" ....>

can it reverse ?

Counteract answered 25/8, 2010 at 3:39 Comment(1)
This has been answered here: #34056476Barbie
L
11

There's a neater way of doing this than the method ShiVik posted. That forced you to manually enter the title to checkbox inside of a tag. If you don't want that, there's a method to re-arrange the order of elements.

In your example, you simply want to change the order of the $format option, like so:

<?php echo $this->Form->input('checkbox', array(
                                  'type'=>'checkbox', 
                                  'format' => array('before', 'input', 'between', 'label', 'after', 'error' ) 
  ) ); ?>
  • Edit, just noticed your post was running cake 1.2. This code is for cake 1.3
Laburnum answered 22/3, 2011 at 15:58 Comment(0)
T
2

You can do this by setting the label to false and using the option "before" to display the label where you want.

<?php echo $form->input('checkbox', 
    array(
      'label'=>false, 
      'type'=>'checkbox',
      'before' => '<label>checkbox</lablel>', 
      'div' => false
 )); ?>

Useful links

If not this, then you can use the Form element specific methods, instead of the automagic form elements.

Then answered 25/8, 2010 at 4:0 Comment(2)
And that's exactly why I prefer the Form element specific methods, instead of wrestling with the options array. ;) Valid answer nonetheless.Stephanestephani
it dont wrestling with options array if checkbox can reverse easily. With inputDefault , you can config fastCounteract
S
1

It's often easier to do things manually if the generic FormHelper::input wrapper doesn't fit your bill:

echo $form->label('fieldname');
echo $form->checkbox('fieldname');

I often don't use FormHelper::input beyond scaffolding.

Stephanestephani answered 25/8, 2010 at 3:56 Comment(2)
sorry but I often use table in form :DCounteract
@meotim And why does that prevent you from writing it this way?Stephanestephani

© 2022 - 2024 — McMap. All rights reserved.