Reputation: 17928
I am outputting a list of checkboxes, with multiple selection, in a CakePHP view. My code looks like this:
<?php echo $this->Form->input('Category', array('multiple' => 'checkbox', 'div' => 'image-checkbox clearfix', 'label' => false, 'data-image' => 'TEXT')); ?>
I want to add the input's label in the data-image
attribute, replacing the TEXT
value. How can I do this?
Thank you very much!
Upvotes: 0
Views: 419
Reputation: 26
The way to do this is with your own helper.
Here:
<?php
class MyAppHelper extends AppHelper {
var $helpers = array( 'Form');
function input( $fieldName, $options = array() ) {
$newOptions['data-image'] = Inflector::humanize( $fieldName );
$options = array_merge(
$options,
$newOptions
);
return $this->Form->input( $fieldName, $options );
}
}
?>
Upvotes: 1