Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 1.3 - Add extra attributes to select menu options

How can I add additional attributes to my select menu option tags? Like this:

<select class="test" name="data[Test][test]">
    <option value="1" data-price="100">My Option</option>
</select>

How do I add the data-price="100" ?

I tried something like this but it didn't work:

<?php
    echo $this->Form->select('test', $options, null, array(
        'class' => 'test',
        'options' => array(
            'data-price' => 100
        )
    ));
?>
like image 950
BadHorsie Avatar asked Jun 05 '26 08:06

BadHorsie


2 Answers

check this out: http://www.dereuromark.de/2012/03/01/some-new-crazy-cakephp-tricks/

"Setting additional attributes for some select options"

like image 121
mark Avatar answered Jun 08 '26 00:06

mark


you can try this
    echo $this->Form->input('test', array(
                        'options' => array(
                                            1=>array(
                                            'data-price' => 100, 
                                            'value' => '1', 
                                            'name' => 'My Option'
                                        )),'class' => 'test')
                                    );
like image 38
Younus Ali Avatar answered Jun 08 '26 00:06

Younus Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!