The select box for forum_categories in the cupcake forum plugin doesn't allow me to select its options. When I rollover the options with my mouse, the highlight stays at 'Select a Forum'. The following is the original
<?php
echo $form->input('forum_category_id', array(
'options' => $forums,
'empty' => '-- '. __d('forum', 'Select a Forum', true) .' --',
'label' => __d('forum', 'Forum Category', true)
));
?>
And i modified it to:
<?php
echo $form->input('Topic.forum_category_id',array(
'empty' => 'Select a Forum',
'options' => $forums
));
?>
The following is the html code it is generating:
<select name="data[Topic][forum_category_id]" id="TopicForumCategoryId">
<option value="">Select a Forum</option>
<optgroup label="Summer Camp">
</optgroup>
</select>
The find stmt in the forumcategory model:
$forums = $this->Forum->find('list', array(
'conditions' => array(
'Forum.status' => 0,
'Forum.accessView <=' => $access,
'Forum.access_level_id' => $accessLevels
),
'order' => 'Forum.orderNo ASC'
));
How can I get rid of the optgroup in the html code above? I just want a simple select box with options and no optgroup like the following:
<select name="data[Topic][forum_category_id]" id="TopicForumCategoryId">
<option value="">Select a Forum</option>
<option value="1">Summer Camp</option>
</select>
thank you.
probably a bit late but
you get opt groups when
your options looks like this :
$arr = array(
'optgroup' => array(
'1','2','3'),
'optgroup2' => array(
'1',2,3)
);
echo $this->Form->input('some',array('options' => $arr));
Try:
echo $this->Form->input('Topic.forum_category_id', array('options' => $forums, 'empty' => 'Select a Forum'));
Related
$getCities = $this->requestAction('objekts/getCities');
This returns me a list with ids and names of cities in alphabetical order.
When I debug $getCities I can see the alphabetical order.
This is the way how I select the data:
$results = $this->find('list', array(
'conditions' => array($and, $andZone),
'fields' => 'REG_ID, REG_NAME',
'group' => 'REG_ID',
'order' => array('REG_NAME ASC')
));
Again, the debug data is in alphabetical order.
But!
echo $this->Form->input('city', array('label' => __('Nach Ort suchen'), 'empty' => __('Bitte wählen'), 'options' => $getCities, 'id' => 'city', 'class' => 'styled-select'));
This is changing the order to it's id's and does not keep my alphabetical order on the city names.
Is there anything I can add to the $this->Form->input to set my order to names instead of ids?
Please advice!
Thanks!!
edit:
this is the debug array
'{"4":"Alar\u00f3","67":"Algaida","99":"Alqueria Blanca","5":"Andratx","6":"Art\u00e1","8":"Bendinat","105":"Biniali","9":"Binissalem","70":"Bunyola",.....
this is the html output
<select id="city" class="styled-select" name="data[Objekt][city]">
<option value="">Bitte wählen</option>
<option value="4">Alaró</option>
<option value="5">Andratx</option>
<option value="6">Artá</option>
....
<option value="67">Algaida</option>
...
<option value="99">Alqueria Blanca</option>
....
In the view:
echo $this->Form->input('Ingredient');
The above populate multiple select list that HTML output as:
<select name="data[Ingredient][Ingredient][]" option="hh" multiple="multiple" id="IngredientIngredient">
<option value="1" selected="selected">Tomato</option>
<option value="2">Spaghetti </option>
<option value="3" selected="selected">Salt</option>
</select>
What I need to know is how to add attributes to the generated <option> tag?
Use the controller to pass selected values:
if ($this->request->is('post') {
// save form
} else {
$this->request->data['Incredient']['Incredient'] = $ids;
}
See here
To add additional attributes like classes you just need to make it a deeper array and you can pass those:
$options = array(
1 => 'One',
2 => array('name' => 'Two', 'value' => 2, 'class' => 'extra'),
3 => 'Three');
echo $this->Form->input('test', array('type' => 'select', 'options' => $options));
The result:
<div class="input select">
<label for="ModelTest">Test</label>
<select name="data[Model][test]" id="ModelTest">
<option value="1">One</option>
<option value="2" class="extra">Two</option>
<option value="3">Three</option>
</select>
</div>
See this
My Example custom tag option in select, by (CakePHP 2 + VueJs 2) is easy.
<?php
$options = array(
array(
'value' => false,
'v-for' => 'obj in data_options_input_id_vuejs',
'name' => '{{obj.text}}',
'v-bind:value' => 'obj.value',
)
);
echo $this->Form->input('input_id', array(
'type' => 'select',
'required' => true,
'class' => 'input-block-level',
'options' => $options,
'v-model:' => 'productos_stocks_padre_combo_select',
));
?>
Hi all, In my case, i want to add code="code-value" to my select option and this code is working for me.
If you want to add extra data to your option, try this code:
//In controller
$chapters = $this->Course->Chapter->find('all', array('fields' => array('name', 'code', 'id')));
// Call the noop function $this->noop() on every element of chapters
$chapters = Hash::map($chapters, "{n}.Chapter", array($this, 'noop'));
// Callback noop function
function noop($option) {
$option['value'] = $option['id'];
unset($option['id']);
return $option;
}
You can see document about Hash:map function here. Good luck.
now i got a table contact.
the contact have 2 row which is id and name.
now i got 3 user in my contact,
1 A
2 B
3 C
question.
how do i make a select input as the code of below ( in cakephp ):
<select name="contact" id="UserField">
<?php for($i=1;$i<=3; $i++) ?>
<option value="1"><?php echo $contact['Contact']['name']; ?></option>
</select>
In your controllers action you can set a list of the names
$names = $this->Contact->find('list', array(
'contain' => array(),
'fields' => array(
'Contact.id',
'Contact.name'
),
'order' => array(
'Contact.name' => 'ASC'
)
));
$this->set(compact('names'));
And then in your view
echo $this->Form->input('contact', array(
'label' => 'Contact',
'options' => $names
));
I'd like to add a select box for searching with the CakeDC Search Plugin. IE:
<select name="field">
<option value="email">Search By Email</option>
<option value="first_name">Search By First Name</option>
</select>
Currently what I have in my VIEW is:
echo $this->Form->create('User', array(
'url' => array_merge(array('action' => 'index'), $this->params['pass'])
));
echo $this->Form->input('email', array('div' => false, 'empty' => true));
echo $this->Form->input('first_name', array('div' => false, 'empty' => true));
This works just fine this way, but I'd like to avoid the multiple input boxes and simplify it with a select box. I could hard it (take the value from the select box and combine it with the value from the input box), but there has to be another way to do it...
Here is my User Module:
public $filterArgs = array(
'email' => array('type' => 'like'),
'first_name' => array('type' => 'like')
);
And this is my Controller:
public function index() {
$this->Prg->commonProcess();
$this->paginate['conditions'] = $this->User->parseCriteria($this->passedArgs);
$this->set('users', $this->paginate());
}
i think you are looking for
echo $this->Form->input('search', array('div' => false, 'empty' => true));
and
public $filterArgs = array(
'search' => array('type' => 'like', 'field'=>array('email', 'first_name')),
);
and
public $presetVars = true;
but you would lose the "AND" of the two inputs in favor of an OR (this is less powerful).
if thats ok for you, this would be the way.
I'm trying to populate a drop down select form with values from a database.
Here is what I have currently.
$modes = Set::combine($this->Setting->find('all', array('conditions' => array('setting_name LIKE' => 'mode_%'))), '{n}.Setting.id','{n}.Setting.setting_name');
$this->set('modes', $modes);
Then in the view, this is what I have
echo $form->select('current_mode',$modes);
That output
<select name="data[Setting][current_mode]" id="SettingCategoryId">
<option value=""></option>
<option value="2">mode_2</option>
<option value="1">mode_1</option>
<option value="3">mode_3</option>
</select>
The output that I have right now almost work but how can I make the output to be like this?
<select name="data[Setting][current_mode]" id="SettingCategoryId">
<option value="mode_2">Title 2</option>
<option value="mode_1">Title 1</option>
<option value="mode_3">Title 3</option>
</select>
Note:
1. no default option with empty value
2. Option's value isn't the id and titles comes from a "title" field in the table
Thanks,
Tee
See http://book.cakephp.org/view/1022/find-list and http://book.cakephp.org/view/1062/displayField.
$settings = $this->Setting->find('list', array(
'conditions' => array('Setting.setting_name LIKE' => 'mode_%'),
'fields' => array('Setting.id', 'Setting.title')
));
$this->set(compact('settings'));
// view
echo $this->Form->input('current_mode', array(
'type' => 'select',
'options' => $settings,
'empty' => false
));
You want to loop through modes and create an option for each mode, like so:
$options = array();
foreach($modes as $mode)
{
$options[$mode] = "Title " . $mode;
}
echo $form->select('current_mode', $options);
You can either put the above logic in your view, or you can do it in your controller, and then set the variable like this:
$this->set("options", $options);
The docs here explain the select element method pretty well:
http://book.cakephp.org/view/1430/select