How to post multiple as array in PHP?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
So that in PHP I can deal with them as :
foreach($_POST['checkboxname'] as $i => $value)
...
php html
add a comment |
So that in PHP I can deal with them as :
foreach($_POST['checkboxname'] as $i => $value)
...
php html
add a comment |
So that in PHP I can deal with them as :
foreach($_POST['checkboxname'] as $i => $value)
...
php html
So that in PHP I can deal with them as :
foreach($_POST['checkboxname'] as $i => $value)
...
php html
php html
asked Dec 30 '09 at 6:52
user198729user198729
23.1k91223323
23.1k91223323
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Do something like this:
<input type="checkbox" name="checkboxArray" />
Note the in the name.
13
+1 Great answer. @unknown Just remember that if none of them are checked, the field won't even be submitted causing theforeach
to fail. Be sure to testisset($_POST['checkboxname'])
prior to theforeach
.
– Doug Neiner
Dec 30 '09 at 6:58
add a comment |
Like this:
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
Just append to their names.
3
There is a little problem !! if i check 5th check box it should be some thing likeArray ( [4] => on )
but it displayArray ( [0] => on )
why it is should i please values likecheckboxname[1]
andcheckboxname[2]
???
– Bilal Maqsood
Sep 26 '15 at 17:07
add a comment |
If you use an array for the checkboxes, you should add a value option as identifier for the single checkboxes, because then the returned array changes from
Array ( [0] => on, [1] => on) to Array ( [0] => value1, [1] => value5 ), which let you identify the checked checkboxes.
add a comment |
for those HTML form elements that can send multiple values to server (like checkboxes, or multiple select boxes), you should use an array like name for your HTML element name. like this:
<input type="checkbox" name="checkboxname" />
also it is recommended that you use an enctype of "multipart/form-data" for your form element.
<form enctype="multipart/form-data" action="target.php" method="post">
then in your PHP scripts you can access the multiple values data as an array, just like you wanted.
Seemsenctype
is unneccesary.
– user198729
Dec 30 '09 at 7:02
add a comment |
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(even){
$("button").click(function(){
var checkvalue = ;
$.each($("input[name='1']:checked"), function(){
checkvalue.push($(this).val());
});
alert("checkvalue: " + checkvalue.join(", "));
});
});
</script>
<body>
<input type="checkbox" name="1" value="1" > 1 <br/>
<input type="checkbox" name="1" value="2"> 2 <br/>
<input type="checkbox" name="1" value="3"> 3 <br/>
<button type="button">Get Values</button>
</body>
</html>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1978781%2fhow-to-post-multiple-input-type-checkbox-as-array-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Do something like this:
<input type="checkbox" name="checkboxArray" />
Note the in the name.
13
+1 Great answer. @unknown Just remember that if none of them are checked, the field won't even be submitted causing theforeach
to fail. Be sure to testisset($_POST['checkboxname'])
prior to theforeach
.
– Doug Neiner
Dec 30 '09 at 6:58
add a comment |
Do something like this:
<input type="checkbox" name="checkboxArray" />
Note the in the name.
13
+1 Great answer. @unknown Just remember that if none of them are checked, the field won't even be submitted causing theforeach
to fail. Be sure to testisset($_POST['checkboxname'])
prior to theforeach
.
– Doug Neiner
Dec 30 '09 at 6:58
add a comment |
Do something like this:
<input type="checkbox" name="checkboxArray" />
Note the in the name.
Do something like this:
<input type="checkbox" name="checkboxArray" />
Note the in the name.
answered Dec 30 '09 at 6:54
KramerCKramerC
922815
922815
13
+1 Great answer. @unknown Just remember that if none of them are checked, the field won't even be submitted causing theforeach
to fail. Be sure to testisset($_POST['checkboxname'])
prior to theforeach
.
– Doug Neiner
Dec 30 '09 at 6:58
add a comment |
13
+1 Great answer. @unknown Just remember that if none of them are checked, the field won't even be submitted causing theforeach
to fail. Be sure to testisset($_POST['checkboxname'])
prior to theforeach
.
– Doug Neiner
Dec 30 '09 at 6:58
13
13
+1 Great answer. @unknown Just remember that if none of them are checked, the field won't even be submitted causing the
foreach
to fail. Be sure to test isset($_POST['checkboxname'])
prior to the foreach
.– Doug Neiner
Dec 30 '09 at 6:58
+1 Great answer. @unknown Just remember that if none of them are checked, the field won't even be submitted causing the
foreach
to fail. Be sure to test isset($_POST['checkboxname'])
prior to the foreach
.– Doug Neiner
Dec 30 '09 at 6:58
add a comment |
Like this:
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
Just append to their names.
3
There is a little problem !! if i check 5th check box it should be some thing likeArray ( [4] => on )
but it displayArray ( [0] => on )
why it is should i please values likecheckboxname[1]
andcheckboxname[2]
???
– Bilal Maqsood
Sep 26 '15 at 17:07
add a comment |
Like this:
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
Just append to their names.
3
There is a little problem !! if i check 5th check box it should be some thing likeArray ( [4] => on )
but it displayArray ( [0] => on )
why it is should i please values likecheckboxname[1]
andcheckboxname[2]
???
– Bilal Maqsood
Sep 26 '15 at 17:07
add a comment |
Like this:
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
Just append to their names.
Like this:
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
<input type="checkbox" name="checkboxname" />
Just append to their names.
answered Dec 30 '09 at 6:54
SarfrazSarfraz
304k65474549
304k65474549
3
There is a little problem !! if i check 5th check box it should be some thing likeArray ( [4] => on )
but it displayArray ( [0] => on )
why it is should i please values likecheckboxname[1]
andcheckboxname[2]
???
– Bilal Maqsood
Sep 26 '15 at 17:07
add a comment |
3
There is a little problem !! if i check 5th check box it should be some thing likeArray ( [4] => on )
but it displayArray ( [0] => on )
why it is should i please values likecheckboxname[1]
andcheckboxname[2]
???
– Bilal Maqsood
Sep 26 '15 at 17:07
3
3
There is a little problem !! if i check 5th check box it should be some thing like
Array ( [4] => on )
but it display Array ( [0] => on )
why it is should i please values like checkboxname[1]
and checkboxname[2]
???– Bilal Maqsood
Sep 26 '15 at 17:07
There is a little problem !! if i check 5th check box it should be some thing like
Array ( [4] => on )
but it display Array ( [0] => on )
why it is should i please values like checkboxname[1]
and checkboxname[2]
???– Bilal Maqsood
Sep 26 '15 at 17:07
add a comment |
If you use an array for the checkboxes, you should add a value option as identifier for the single checkboxes, because then the returned array changes from
Array ( [0] => on, [1] => on) to Array ( [0] => value1, [1] => value5 ), which let you identify the checked checkboxes.
add a comment |
If you use an array for the checkboxes, you should add a value option as identifier for the single checkboxes, because then the returned array changes from
Array ( [0] => on, [1] => on) to Array ( [0] => value1, [1] => value5 ), which let you identify the checked checkboxes.
add a comment |
If you use an array for the checkboxes, you should add a value option as identifier for the single checkboxes, because then the returned array changes from
Array ( [0] => on, [1] => on) to Array ( [0] => value1, [1] => value5 ), which let you identify the checked checkboxes.
If you use an array for the checkboxes, you should add a value option as identifier for the single checkboxes, because then the returned array changes from
Array ( [0] => on, [1] => on) to Array ( [0] => value1, [1] => value5 ), which let you identify the checked checkboxes.
answered Jan 19 '17 at 13:31
JestaBluntJestaBlunt
5810
5810
add a comment |
add a comment |
for those HTML form elements that can send multiple values to server (like checkboxes, or multiple select boxes), you should use an array like name for your HTML element name. like this:
<input type="checkbox" name="checkboxname" />
also it is recommended that you use an enctype of "multipart/form-data" for your form element.
<form enctype="multipart/form-data" action="target.php" method="post">
then in your PHP scripts you can access the multiple values data as an array, just like you wanted.
Seemsenctype
is unneccesary.
– user198729
Dec 30 '09 at 7:02
add a comment |
for those HTML form elements that can send multiple values to server (like checkboxes, or multiple select boxes), you should use an array like name for your HTML element name. like this:
<input type="checkbox" name="checkboxname" />
also it is recommended that you use an enctype of "multipart/form-data" for your form element.
<form enctype="multipart/form-data" action="target.php" method="post">
then in your PHP scripts you can access the multiple values data as an array, just like you wanted.
Seemsenctype
is unneccesary.
– user198729
Dec 30 '09 at 7:02
add a comment |
for those HTML form elements that can send multiple values to server (like checkboxes, or multiple select boxes), you should use an array like name for your HTML element name. like this:
<input type="checkbox" name="checkboxname" />
also it is recommended that you use an enctype of "multipart/form-data" for your form element.
<form enctype="multipart/form-data" action="target.php" method="post">
then in your PHP scripts you can access the multiple values data as an array, just like you wanted.
for those HTML form elements that can send multiple values to server (like checkboxes, or multiple select boxes), you should use an array like name for your HTML element name. like this:
<input type="checkbox" name="checkboxname" />
also it is recommended that you use an enctype of "multipart/form-data" for your form element.
<form enctype="multipart/form-data" action="target.php" method="post">
then in your PHP scripts you can access the multiple values data as an array, just like you wanted.
answered Dec 30 '09 at 6:58
farzadfarzad
7,26952738
7,26952738
Seemsenctype
is unneccesary.
– user198729
Dec 30 '09 at 7:02
add a comment |
Seemsenctype
is unneccesary.
– user198729
Dec 30 '09 at 7:02
Seems
enctype
is unneccesary.– user198729
Dec 30 '09 at 7:02
Seems
enctype
is unneccesary.– user198729
Dec 30 '09 at 7:02
add a comment |
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(even){
$("button").click(function(){
var checkvalue = ;
$.each($("input[name='1']:checked"), function(){
checkvalue.push($(this).val());
});
alert("checkvalue: " + checkvalue.join(", "));
});
});
</script>
<body>
<input type="checkbox" name="1" value="1" > 1 <br/>
<input type="checkbox" name="1" value="2"> 2 <br/>
<input type="checkbox" name="1" value="3"> 3 <br/>
<button type="button">Get Values</button>
</body>
</html>
add a comment |
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(even){
$("button").click(function(){
var checkvalue = ;
$.each($("input[name='1']:checked"), function(){
checkvalue.push($(this).val());
});
alert("checkvalue: " + checkvalue.join(", "));
});
});
</script>
<body>
<input type="checkbox" name="1" value="1" > 1 <br/>
<input type="checkbox" name="1" value="2"> 2 <br/>
<input type="checkbox" name="1" value="3"> 3 <br/>
<button type="button">Get Values</button>
</body>
</html>
add a comment |
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(even){
$("button").click(function(){
var checkvalue = ;
$.each($("input[name='1']:checked"), function(){
checkvalue.push($(this).val());
});
alert("checkvalue: " + checkvalue.join(", "));
});
});
</script>
<body>
<input type="checkbox" name="1" value="1" > 1 <br/>
<input type="checkbox" name="1" value="2"> 2 <br/>
<input type="checkbox" name="1" value="3"> 3 <br/>
<button type="button">Get Values</button>
</body>
</html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(even){
$("button").click(function(){
var checkvalue = ;
$.each($("input[name='1']:checked"), function(){
checkvalue.push($(this).val());
});
alert("checkvalue: " + checkvalue.join(", "));
});
});
</script>
<body>
<input type="checkbox" name="1" value="1" > 1 <br/>
<input type="checkbox" name="1" value="2"> 2 <br/>
<input type="checkbox" name="1" value="3"> 3 <br/>
<button type="button">Get Values</button>
</body>
</html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(even){
$("button").click(function(){
var checkvalue = ;
$.each($("input[name='1']:checked"), function(){
checkvalue.push($(this).val());
});
alert("checkvalue: " + checkvalue.join(", "));
});
});
</script>
<body>
<input type="checkbox" name="1" value="1" > 1 <br/>
<input type="checkbox" name="1" value="2"> 2 <br/>
<input type="checkbox" name="1" value="3"> 3 <br/>
<button type="button">Get Values</button>
</body>
</html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(even){
$("button").click(function(){
var checkvalue = ;
$.each($("input[name='1']:checked"), function(){
checkvalue.push($(this).val());
});
alert("checkvalue: " + checkvalue.join(", "));
});
});
</script>
<body>
<input type="checkbox" name="1" value="1" > 1 <br/>
<input type="checkbox" name="1" value="2"> 2 <br/>
<input type="checkbox" name="1" value="3"> 3 <br/>
<button type="button">Get Values</button>
</body>
</html>
answered Nov 16 '18 at 12:43
sakthi sudhansakthi sudhan
655
655
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1978781%2fhow-to-post-multiple-input-type-checkbox-as-array-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown