How do I save every option of a select box in an array? (PHP) [closed]












-2















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)?










share|improve this 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 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
















-2















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)?










share|improve this 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 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














-2












-2








-2








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)?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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



















  • 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

















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












1 Answer
1






active

oldest

votes


















3














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);





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    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);





    share|improve this answer






























      3














      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);





      share|improve this answer




























        3












        3








        3







        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);





        share|improve this answer















        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);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 2 at 4:41









        Ali

        1,1791421




        1,1791421










        answered Jan 2 at 3:51









        Jun PanJun Pan

        315




        315

















            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith