Unable to set_select for multiple select form element - codeigniter

<select multiple name="skills[]">
<option value=".NET">.Net<?php echo set_select('skills[]', '.NET'); ?></option>
<option value="JAVA">Java<?php echo set_select('skills[]', 'JAVA'); ?></option>
<option value="php">PHP<?php echo set_select('skills[]', 'php'); ?></option>
<option value="cloud">Cloud<?php echo set_select('skills[]', 'cloud'); ?></option>
</select></td>
Hello here I am trying to set_select() for select multiple but not able to do. Need help, how Can I do that.. Thanks.
Sorry but tried following code it is working, :)
<select multiple name="skills[]">
<option value=".NET"<?php echo set_select('skills', '.NET'); ?>>.Net</option>
<option value="JAVA"<?php echo set_select('skills', 'JAVA'); ?>>Java</option>
<option value="php"<?php echo set_select('skills', 'php'); ?>>PHP</option>
<option value="cloud"<?php echo set_select('skills', 'cloud'); ?>>Cloud</option>
</select>

You can do that by specifying the third parameter of set_select, if set to TRUE it sets an item as default. For selecting all the options in your example just try the following code:
<select name="myselect[]" multiple>
<option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
<option value="two" <?php echo set_select('myselect', 'two',TRUE); ?> >Two</option>
<option value="three" <?php echo set_select('myselect', 'three',TRUE); ?> >Three</option>
</select>
See info here

Related

Simple select option set_value in codeigniter

I have simple select for gender option :
<select class="form-control show-tick" name="kelamin" required="true">
<option value="">-- Please select --</option>
<option value="L" >Laki-Laki</option>
<option value="P">Perempuan</option>
</select>
How to set_value on select option like
<input type="text" name="nama" class="form-control" value="<?= set_value('nama'); ?>" required="true">
Use the set_select function.
<select class="form-control show-tick" name="kelamin" required="true">
<option value="" <?= set_select('kelamin', '', TRUE); ?> >-- Please select --</option>
<option value="L" <?= set_select('kelamin', 'L'); ?> >Laki-Laki</option>
<option value="P" <?= set_select('kelamin', 'P'); ?> >Perempuan</option>
</select>

Code igniter update function on dropdown menu

i have this update function on my codeigniter
my controller is
public function updatepersonalinfo(){
$id = $_GET['id'];
$data['content'] = $this->Employees_Model->personalinfo($id); // this is current information to be updated
$data['content1'] = $this->Employees_Model->nationality(); // this is select box value
$data['content_view'] = 'Employees/edit_personalinfo';
$this->templates->admin_template($data);
}
then my view for one of the select box is
<select class="form-control" name = "BLOOD_TYPE">
<option value="<?php echo $content->BLOOD_TYPE; ?>"><?php echo $content->BLOOD_TYPE; ?></option>
<option value="A"> A </option>
<option value="B"> B </option>
<option value="AB"> AB </option>
<option value="O"> O </option>
</select>
what happens here is that for example, the value that to be updated is A
it will become
what i wanted to do is, for example, the value i will update to the database is B the update function will show something like this.

set_select() is marking every option as selected

The set_select function of CodeIgniter 3 is always selecting the last option of any select input when I click to edit some existing item.
I will just show the first two selects, which is below:
<div class="form-group col-md-6">
<label for="id_marca">Marca do Carro</label>
<select id="id_marca" name="id_marca" class="form-control" required>
<option value="" selected disabled>Selecione</option>
<?php foreach ($marcas as $m) { ?>
<option value="<?php echo $m['id']; ?>" <?php echo set_select('id_marca', $m['id'], true); ?>>
<?php echo $m['nome_marca']; ?>
</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-6">
<label for="id_modelo">Modelo do Carro</label>
<select id="id_modelo" name="id_modelo" class="form-control" required>
<option value="" selected disabled>Selecione</option>
<?php foreach ($modelos as $m) { ?>
<option value="<?php echo $m['id']; ?>" <?php echo set_select('id_modelo', $m['id'], TRUE); ?>>
<?php echo $m['nome_modelo']; ?>
</option>
<?php } ?>
</select>
</div>
Below is a screenshot of the problem. As it can be seen in the Inspector, every option is selected.
I made it work few days ago, and now magically does not work anymore.
The problem with your code that you put true as third parameter in all of your option
set_select('first parameter will be name', 'second parameter will be the value', 'third parameter will be the "true/false" which make this value selected or not')
i think you need to look at this
UPDATE
$options = array(
'small' => 'Small Shirt',
'med' => 'Medium Shirt',
'large' => 'Large Shirt',
'xlarge' => 'Extra Large Shirt',
);
$shirts_on_sale = array('small', 'large');
echo form_dropdown('shirts', $options, 'large');
// Would produce:
<select name="shirts">
<option value="small">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>
you could see this
Sorry about that
UPDATE 2
<select name="myselect">
<option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
<option value="two" <?php echo set_select('myselect', 'two'); ?> >Two</option>
<option value="three" <?php echo set_select('myselect', 'three'); ?> >Three</option>
</select>

codeigniter dropdown select data from database

<select class="form-control">
<?php
$flag=0;
foreach ($result as $row) { ?>
if(flag==0)
{
<option value="<?php echo $row->tbl_group_id; selected="selected"?>" ><?php echo $row->tbl_group_rolename; ?></option>
flag=1;
}
else
{
<option value="<?php echo $row->tbl_group_id;?>" ><?php echo $row->tbl_group_rolename; ?></option>
}
} ?>
<option value="name">One</option>
<option value="email">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
I have one dropdownbox(on login page) in which I have to get all the data from my database and it must be shown dynamically.
My form is created in bootstrap way.
I want all the data to come from table, dynamically in dropdown and when I select it; I can register as that person for example admin/user.
I have tried nothing till now; nothing comes in my mind.
First of all, you have to fix your PHP start and end tags. This is necessary because otherwise the PHP interpreter does not know what to evaluate.
The rest is pretty straightforward. I changed your $flag to a boolean in order to check whether the current entry is the first entry and therefore should be selected. Also I removed the duplicated code and introduced an if that outputs selected="selected" for the first option.
<select class="form-control">
<?php
$first=true; // Used to select the first element
foreach ($result as $row): /* everything between here and 'endforeach' is part of the loop */ ?>
<option value="<?php echo $row->tbl_group_id ?>" <?php if ($first) echo 'selected="selected"' ?>>
<?php echo $row->tbl_group_rolename ?>
</option>
<?php if ($first) $first = false /* this makes sure that only one option element is selected */ ?>
<?php endforeach ?>
<option value="name">One</option>
<option value="email">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
The loop iterates over the rows. Note that the colon after the foreach statement uses an alternative syntax that makes it easier to read if mixed with HTML:
<?php foreach ($result as $row): ?>
<!-- HTML code here that gets printed once for each $row -->
<?php endforeach ?>
You then put some PHP code inside the HTML to make it dynamic.
<?php if ($first) echo 'selected="selected"' ?>
The code above prints selected="selected" if $first is true. After the first iteration $first becomes false:
<?php if ($first) $first = false ?>
<select class="form-control">
<?php
foreach ($result as $row) {
$sel = ($row->tbl_group_id == $someId)?'selected="selected"':'';
?>
<option value="<?php echo $row->tbl_group_id;?>" <?php echo $sel; ?> ><?php echo $row->tbl_group_rolename; ?></option>
<?php } ?>
<option value="name">One</option>
<option value="email">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>

How to add currency symbols into the currency list?

How can I add currency symbols into the currency list?
This is the code,
<?php if($this->getCurrencyCount() > 1): ?>
<div class="form-micro">
<select onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
<?php foreach ($this->getCurrencies() as $_code => $_name): ?>
<option value="<?php echo $this->getSwitchCurrencyUrl($_code)?>"
<?php if($_code == $this->getCurrentCurrencyCode()): ?>
selected="SELECTED"
<?php endif; ?>>
<?php echo $_name ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
will output,
<option ...>Euro</option>
<option ...>British Pound</option>
<option ...>Danish Krone</option>
<option ...>Swedish Krona</option>
<option ...>Swiss Franc</option>
<option ...>United States Dollars</option>
But I need to add their symbols after the text,
<option ...>Euro €</option>
<option ...>British Pound £</option>
<option ...>Danish Krone DKK</option>
<option ...>Swedish Krona SEK</option>
<option ...>Swiss Franc CHF</option>
<option ...>United States Dollars $</option>
Is it possible?
Yes,Tealou ,it is possible ,you can get this using below code
Mage::app()->getLocale()->currency($cuurencycode)->getSymbol();
Your modified code is
<?php if($this->getCurrencyCount() > 1): ?>
<div class="form-micro">
<select onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
<?php foreach ($this->getCurrencies() as $_code => $_name): ?>
<option value="<?php echo $this->getSwitchCurrencyUrl($_code)?>"
<?php if($_code == $this->getCurrentCurrencyCode()): ?>
selected="SELECTED"
<?php endif; ?>>
<?php echo $_name ?><?php Mage::app()->getLocale()->currency($_code)->getSymbol(); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>

Resources