Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 675 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CakePHP 1.3 - Add extra attributes to select menu options

#1
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
)
));
?>
Reply

#2
You have to manually build the select HTML

also you can refer

[To see links please register here]

Reply

#3
check this out:

[To see links please register here]


"Setting additional attributes for some select options"
Reply

#4
you can try this
echo $this->Form->input('test', array(
'options' => array(
1=>array(
'data-price' => 100,
'value' => '1',
'name' => 'My Option'
)),'class' => 'test')
);
Reply

#5
You can do it this way:

$options = array(
...
array('name' => 'United states', 'value' => 'USA', 'title' => 'the title that you want', 'class' => 'something'),
array('name' => 'USA', 'value' => 'USA', 'title' => 'the other title that you want', 'class' => 'otherthing'),
);

echo $this->Form->input('test', array('type'=>'select', 'options'=>$options));
Reply

#6
In cakephp 4

[look for documentation][1]

Controller

$countries = $this->Countries->find('all')->where([
'active' => 1
]);

$options = $examples->map(function ($value, $key) {
return [
'value' => $value->id,
'text' => $value->name,
'data-flag' => $value->iso_code
];
});

In view/template

<?= $this->Form->control('country_residence_id', [
'label' => false,
'options' => $countries,
'class' => 'form-control select2-flag-search',
'data-placeholde' => __('Select Country')
]) ?>


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through