Giter Site home page Giter Site logo

Comments (8)

nandalal avatar nandalal commented on April 27, 2024 1

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.

magicleaves avatar magicleaves commented on April 27, 2024

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.

basv avatar basv commented on April 27, 2024

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.

magicleaves avatar magicleaves commented on April 27, 2024

Thank you. I have applied that solution and it works fine.

from codeigniter.

basv avatar basv commented on April 27, 2024

Cool :)

from codeigniter.

petsagouris avatar petsagouris commented on April 27, 2024

@basv Could you put up a pull request for this since you have working changes?

from codeigniter.

basv avatar basv commented on April 27, 2024

I did, 8 months ago...

#322

from codeigniter.

petsagouris avatar petsagouris commented on April 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.