How do I save every option of a select box in an array? (PHP) [closed]
Let's say I have an select box: <select name="cart" id="cart" size="5"></select>
This box is filled with 5 different options.
If I write $data = $_POST['cart'];
it will only save the option, which is currently selected. How can I save every option (so the ones which are not selected as well)?
php html arrays forms input
closed as too broad by Funk Forty Niner, Book Of Zeus, Ian Lim, greg-449, Springer F Jan 2 at 11:13
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 1 more comment
Let's say I have an select box: <select name="cart" id="cart" size="5"></select>
This box is filled with 5 different options.
If I write $data = $_POST['cart'];
it will only save the option, which is currently selected. How can I save every option (so the ones which are not selected as well)?
php html arrays forms input
closed as too broad by Funk Forty Niner, Book Of Zeus, Ian Lim, greg-449, Springer F Jan 2 at 11:13
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
if you want more than one value then you have to allow multiple values withmultiple
w3schools.com/tags/att_select_multiple.asp
– daremachine
Jan 2 at 3:11
Use themultiple
attribute.
– Xufox
Jan 2 at 3:12
1
FYI you can not send unselected values because it does not make sense. If you need them you load it in your post script.
– daremachine
Jan 2 at 3:13
@daremachine how can I load the ones which are not selected? This is my problem.
– Telkor
Jan 2 at 3:42
1
That literally defeats the purpose of a select box. Why do you need all the values and how do you intend to differentiate which was selected and what was not?
– Second2None
Jan 2 at 4:15
|
show 1 more comment
Let's say I have an select box: <select name="cart" id="cart" size="5"></select>
This box is filled with 5 different options.
If I write $data = $_POST['cart'];
it will only save the option, which is currently selected. How can I save every option (so the ones which are not selected as well)?
php html arrays forms input
Let's say I have an select box: <select name="cart" id="cart" size="5"></select>
This box is filled with 5 different options.
If I write $data = $_POST['cart'];
it will only save the option, which is currently selected. How can I save every option (so the ones which are not selected as well)?
php html arrays forms input
php html arrays forms input
edited Jan 2 at 4:48


Funk Forty Niner
1
1
asked Jan 2 at 3:08
TelkorTelkor
1
1
closed as too broad by Funk Forty Niner, Book Of Zeus, Ian Lim, greg-449, Springer F Jan 2 at 11:13
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by Funk Forty Niner, Book Of Zeus, Ian Lim, greg-449, Springer F Jan 2 at 11:13
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
if you want more than one value then you have to allow multiple values withmultiple
w3schools.com/tags/att_select_multiple.asp
– daremachine
Jan 2 at 3:11
Use themultiple
attribute.
– Xufox
Jan 2 at 3:12
1
FYI you can not send unselected values because it does not make sense. If you need them you load it in your post script.
– daremachine
Jan 2 at 3:13
@daremachine how can I load the ones which are not selected? This is my problem.
– Telkor
Jan 2 at 3:42
1
That literally defeats the purpose of a select box. Why do you need all the values and how do you intend to differentiate which was selected and what was not?
– Second2None
Jan 2 at 4:15
|
show 1 more comment
if you want more than one value then you have to allow multiple values withmultiple
w3schools.com/tags/att_select_multiple.asp
– daremachine
Jan 2 at 3:11
Use themultiple
attribute.
– Xufox
Jan 2 at 3:12
1
FYI you can not send unselected values because it does not make sense. If you need them you load it in your post script.
– daremachine
Jan 2 at 3:13
@daremachine how can I load the ones which are not selected? This is my problem.
– Telkor
Jan 2 at 3:42
1
That literally defeats the purpose of a select box. Why do you need all the values and how do you intend to differentiate which was selected and what was not?
– Second2None
Jan 2 at 4:15
if you want more than one value then you have to allow multiple values with
multiple
w3schools.com/tags/att_select_multiple.asp– daremachine
Jan 2 at 3:11
if you want more than one value then you have to allow multiple values with
multiple
w3schools.com/tags/att_select_multiple.asp– daremachine
Jan 2 at 3:11
Use the
multiple
attribute.– Xufox
Jan 2 at 3:12
Use the
multiple
attribute.– Xufox
Jan 2 at 3:12
1
1
FYI you can not send unselected values because it does not make sense. If you need them you load it in your post script.
– daremachine
Jan 2 at 3:13
FYI you can not send unselected values because it does not make sense. If you need them you load it in your post script.
– daremachine
Jan 2 at 3:13
@daremachine how can I load the ones which are not selected? This is my problem.
– Telkor
Jan 2 at 3:42
@daremachine how can I load the ones which are not selected? This is my problem.
– Telkor
Jan 2 at 3:42
1
1
That literally defeats the purpose of a select box. Why do you need all the values and how do you intend to differentiate which was selected and what was not?
– Second2None
Jan 2 at 4:15
That literally defeats the purpose of a select box. Why do you need all the values and how do you intend to differentiate which was selected and what was not?
– Second2None
Jan 2 at 4:15
|
show 1 more comment
1 Answer
1
active
oldest
votes
You can't get the unselected value from $_POST
, but you can do as follows
$allOption = [
1,2,3,4,5
];
$selected = $_POST['cart'];
$unselected = array_diff($allOption, $selected);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't get the unselected value from $_POST
, but you can do as follows
$allOption = [
1,2,3,4,5
];
$selected = $_POST['cart'];
$unselected = array_diff($allOption, $selected);
add a comment |
You can't get the unselected value from $_POST
, but you can do as follows
$allOption = [
1,2,3,4,5
];
$selected = $_POST['cart'];
$unselected = array_diff($allOption, $selected);
add a comment |
You can't get the unselected value from $_POST
, but you can do as follows
$allOption = [
1,2,3,4,5
];
$selected = $_POST['cart'];
$unselected = array_diff($allOption, $selected);
You can't get the unselected value from $_POST
, but you can do as follows
$allOption = [
1,2,3,4,5
];
$selected = $_POST['cart'];
$unselected = array_diff($allOption, $selected);
edited Jan 2 at 4:41


Ali
1,1791421
1,1791421
answered Jan 2 at 3:51


Jun PanJun Pan
315
315
add a comment |
add a comment |
if you want more than one value then you have to allow multiple values with
multiple
w3schools.com/tags/att_select_multiple.asp– daremachine
Jan 2 at 3:11
Use the
multiple
attribute.– Xufox
Jan 2 at 3:12
1
FYI you can not send unselected values because it does not make sense. If you need them you load it in your post script.
– daremachine
Jan 2 at 3:13
@daremachine how can I load the ones which are not selected? This is my problem.
– Telkor
Jan 2 at 3:42
1
That literally defeats the purpose of a select box. Why do you need all the values and how do you intend to differentiate which was selected and what was not?
– Second2None
Jan 2 at 4:15