1

I am a bit new to CakePhp. I have an input that is a checkbox with a label and i would like to assign a class to the label.

Here is what I have so far:

echo $this->Form->input('', array(
               'type' => 'checkbox',
               'label' => 'I agree to the conditions',
               'separator' => '</div><div class="controls">',
               'format' => array('before', 'input', 'label','between', 'after','error'),

               ));

the html I would like to have is something like this:

<div class="control-group ">
            <div class="controls">
                <input type="checkbox" name="" id="" '> 
                <label class='small_text'> <!-- can't get this one in cake -->
                   I agree to the conditions
            </label>
            </div>
        </div>

I got almost all right but i miss the class small-text for the label. Any idea on how to achieve that? thanx!

2 Answers 2

4

Use following which gives class to label

echo $this->Form->input('', array(
'type' => 'checkbox',
'label' => array('class' => 'small_text','text'=>'I agree to the conditions'),
'separator' => '</div><div class="controls">',
'format' => array('before', 'input', 'label','between', 'after','error'),

));

Explanation : 'label' => array('class' => 'small_text','text'=>'I agree to the conditions'), means you are Not Only giving text for label , but also class to label by specifying the parameter class . By default as per your code , only Text was passed , so it displayed only text. I added class parameter which specifies class property/attribute for label.

Sign up to request clarification or add additional context in comments.

Comments

0

I prefer the one given by jQuery.PHP.Magento.com but I'll post my solution as well.... I come up with something like this:

$termsAndConditions =  $this->Html->link('Terms And Conditions', 'conditions', array('target' => '_blank'));

$labelConditions = $this->Form->label('agreeToConditions', 'I agree to the  '.$termsAndConditions.' of this site', array(
            'class' => 'small_text',
        ));

        echo $this->Form->input('agreeToConditions', array(
            'type' => 'checkbox',
            'label' => $labelConditions,
            'separator' => '</div><div class="controls">',
            'format' => array('before', 'input', 'label','between', 'after','error'),

            )); 
        ?>

I needed to add a link to the label that I didn't mention in the question.

However I think the one provided by jQuery.php.Magento is a bit better as it is more compact and easy to read

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.