Comments (8)
I want to display the data in select-drop down not only hard-code value, but also the value from master table what can i do....?? i got a solution from google the code is like this below i mentioned
<select class="form-control" id="sel2" name="branch">
<option value="">---Select Choice---</option>
<?php
foreach ($branch as $each) {
?>
<option value="<?=$each['bid']?>"<?php echo set_select('branch', '$each["branch_name"]'); ?> ><?=$each['branch_name']?></option>
<?php
}
?>
</select>
But after that i submit the form but this drop-down value is missing please help
from codeigniter.
The bugfix can be applied manually but you have to change your code where you use set_select. That means each time updating codeigniter will need manuel update in two files again and again.
from codeigniter.
Meh I had written a proper explanation of the bugfix in BitBucket. Here's a part of it.
The problem
Ok, so as explained above the set_select() function checks the full post-array for each select box and can not differentiate between the different select boxes if you use arrays as field names.
The post-array contains the following array for select boxes with an array as field name, the name of this array is ofc the same as the name of the select box:
Array
(
[0] => value1
[1] => value2
[2] => value3
[3] => value4
)
Key 0 contains the selected value from the first select box, key 1 the second, and so on....
The current set_select() function uses all values in the post-array for each select box, so if you select value4 in the 4th select box it will be selected in all the select boxes! So, the set_select() function somehow needs to know which key in the post-array should be used for which select box. It can't use the name of the select box because obviously they are the same if you use an array as field name :)
The theoretical solution
My idea was to add an extra, optional, argument to the set_select() function. This extra argument passes an integer to the function which is only used if we are dealing with an array. The integer you pass must equal the key in the post-array you want this set_select() to use to determine which value should be set as selected. So if you are using set_select() on your first select box the integer passes should be 0, on your second select box it should be 1, and so on.... Now the set_select() function does know which key should be used and is able to set the correct value as selected for all your select boxes with an array as field name, YAY!
My fix continues to work for normal field names, it doesn't require any code updates for anyone but it does give us the opportunity to properly work with re-population with arrays as field names! HTML will look like this:
<select name="myselect[]">
<option value="one" <?php echo set_select('myselect[]', 'one', TRUE, 0); ?> >One</option>
<option value="two" <?php echo set_select('myselect[]', 'two', FALSE, 0); ?> >Two</option>
<option value="three" <?php echo set_select('myselect[]', 'three', FALSE, 0); ?> >Three</option>
</select>
<select name="myselect[]">
<option value="one" <?php echo set_select('myselect[]', 'one', TRUE, 1); ?> >One</option>
<option value="two" <?php echo set_select('myselect[]', 'two', FALSE, 1); ?> >Two</option>
<option value="three" <?php echo set_select('myselect[]', 'three', FALSE, 1); ?> >Three</option>
</select>
A pull request will be provided soon!
from codeigniter.
Thank you. I have applied that solution and it works fine.
from codeigniter.
Cool :)
from codeigniter.
@basv Could you put up a pull request for this since you have working changes?
from codeigniter.
I did, 8 months ago...
from codeigniter.
Issue queue cleanup notes (comment to be deleted)
labels: +Has pull request (#322) -Bitbucket Open
@basv Thanks for the pull request ;)
from codeigniter.
Related Issues (20)
- Deprecated Deprecations of Expected Exceptions HOT 1
- CodeIgniter + Session usage with Redis is slow HOT 4
- mysqli_driver version_compare issue CI 3.1.13
- Controller classes must exist as files (why??)
- Drop support for PHP < 8.1 HOT 10
- Crazy error, php-api/system/database/DB_driver.php --------> function escape($str) error HOT 4
- Email library does not send email through SMTP on PHP 8.2
- Upcoming deprecations in PHP 8.3 HOT 2
- Codeigniter 3.1.4 and PHP 8.1 HOT 4
- mysqli num_rows always return 0 HOT 1
- Session Lost for CI 3.1.13 on Page Refresh HOT 4
- Misleading docblock of the file_get_info function
- xss_clean % error HOT 1
- Bug: inconsistent behavior of Query Builder limit 0 HOT 8
- bug: codeigniter3 db->or_where_not_in(...) HOT 1
- Are there plans for CodeIgniter 3.1.14? HOT 2
- XSS when data is passed on to the web application via an API HOT 3
- only laravel HOT 1
- Upcoming deprecation of mt_rand()
- BUG: session_write_close(): Failed to write session data using user defined save handler. Localised with suggested fix HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeigniter.