Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePhp adding label to select formhelper

Tags:

php

cakephp

I would like to add a label to my select form helper however I am not quite sure how to do this in cake v2+.

This is my current code which does not work:

echo $this->Form->select('format_id', $formats, array('label'=>'Format:'));
like image 444
InvalidSyntax Avatar asked Dec 14 '22 21:12

InvalidSyntax


2 Answers

You can do this:

 echo $this->Form->label('Format');
 echo $this->Form->select('format_id', $formats, array());

or

 echo $this->Form->input('format_id', array('label'=>'Format', 'type'=>'select', 'options'=>$formats));
like image 95
decodingpanda Avatar answered Dec 17 '22 10:12

decodingpanda


I found the answer, it is because you need to use Form->input like so...

echo $this->Form->input('format_id', array('label'=>'Format: ', 'type'=>'select', 'options'=>$formats));
like image 22
InvalidSyntax Avatar answered Dec 17 '22 11:12

InvalidSyntax