• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dropdown with multiple

#1
Hello, I wanted to use dropdown with multiple attribute using helper forms:
PHP Code:
<?= form_dropdown('dpd', array(
 
       '1' => 'First',
 
       '2' => 'Second',
 
       '3' => 'third',
 
       '4' => 'fourth',
), 
'2''class = "form-control" multiple');?>
PHP Code:
$drpdown $this->request->getPost('dpd'); 

I choose several values, expect to get something like an array...

but instead I get:
Code:
string '3' (length=1)

Yes, this value also participates in the sample, but it is chosen last. There should be 2 more.

What have I done wrong? Thanks!
Reply

#2
The name of the dropdown has to be array as well:
PHP Code:
form_dropdown('dpd[]', array(
// ... 

This only applies to HTML element, and when accessing POST variables, you only reference dpd, not dpd[].
Reply

#3
(07-22-2018, 01:46 AM)Pertti Wrote: The name of the dropdown has to be array as well:
PHP Code:
form_dropdown('dpd[]', array(
// ... 

This only applies to HTML element, and when accessing POST variables, you only reference dpd, not dpd[].

Forgive me, I forgot about this, similar situation was with multi-uploading files.

Thank you!
Reply

#4
You could also use this.

PHP Code:
<?= form_multiselect('dpd[]', ['1' => 'First''2' => 'Second''3' => 'third''4' => 'fourth',], '2'"class = 'form-control'"); ?>
Reply

#5
(07-26-2018, 03:09 PM)Друг друга. Wrote: You could also use this.

PHP Code:
<?= form_multiselect('dpd[]', ['1' => 'First''2' => 'Second''3' => 'third''4' => 'fourth',], '2'"class = 'form-control'"); ?>

Thank you, but what is the difference between an example taken from the documentation where the classical array record is used and the reduced record of the array from yours?
Reply

#6
(07-27-2018, 04:05 AM)Nome Wrote: Thank you, but what is the difference between an example taken from the documentation where the classical array record is used and the reduced record of the array from yours?

The array syntax makes no difference and isn't the point. The point is the use of form_multiselect instead fo form_dropdown.

Creating an array using the array() language construct, e.g.
PHP Code:
array('1' => 'First''2' => 'Second''3' => 'third''4' => 'fourth',) 
or using the short syntax, e.g.
PHP Code:
['1' => 'First''2' => 'Second''3' => 'third''4' => 'fourth',] 
produces the exact same array, the only difference is the code style..

I'm just in the habit of using the short syntax because I like typing less to get the same results. Sorry if that caused confusion.
Reply

#7
(07-27-2018, 05:20 AM)dave friend Wrote: The array syntax makes no difference and isn't the point. The point is the use of form_multiselect instead fo form_dropdown.

No, I'm sorry I did not notice that there is form_multiselect .  You are right =)
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.