0
votes

I have problem with displaying required fields in Cakephp 2.4.2.

If I use

$this->Form->input('username');

in rendered html I have

<div class="input text required">
    <label for="UserUsername">Username</label>
    <input name="data[User][username]" type="text" id="UserUsername" required="required"/>
</div>

and the label has asterisk: username*

If I want to use Twitter Bootstrap with its horizontal form style, my input changes to something like this:

<div class="form-horizontal">
    <div class="form-group">
        <label for="username" class="col-xs-3"></label>
        <div class="col-xs-4">
            <?php echo $form->input('username',array('id' => 'username','label' => false)); ?>
        </div>
    </div>
</div>

which results in

<div class="form-horizontal">
    <div class="form-group">
        <label for="username" class="col-xs-3">Username</label>
        <div class="col-xs-4">
            <div class="input text required">
                <input name="data[User][username]" id="username" type="text" required="required"/>
            </div>
        </div>
    </div>
</div>

and label lost asterisk: username

Basically, if Cake input has option 'label' => false it will have input label without asterisk:

$this->Form->label('User.username');
$this->Form->input('username',array('label' => false));

results in

<label for="UserUsername">Username</label>
<div class="input text required">
    <input name="data[User][username]" type="text" id="UserUsername" required="required"/>
</div>

and no asterisk in the label.

What would be the way to have asterisk in the label of the required field while using Cake Form Helper?

3

3 Answers

1
votes

I suggest you check out Boost Cake plugin for twitter bootstrap integration with CakePHP.

1
votes

If you're like me and just searching how to display the asterisk on all required inputs, (when using the BoostCake plugin), this css worked for me:

.required label:after {
    color: #d00;
    content: " *"
}
0
votes

What would be the way to have asterisk in the label of the required field while using Cake Form Helper?

Are you trying to hardcode an asterisk in the label? This should do the trick

$this->Form->input('username', array('label'=> 'Enter username here*'));