Desperate-gettin à cocher valeurs POST (PHP)
- JackDaRippaZ
- Newbie


- Inscription: Juin 25, 2004
- Messages: 11
- Status: Offline
hey les peuples
J'ai vraiment besoin de savoir comment obtenir les valeurs d'un tableau de case à cocher en utilisant la méthode POST en PHP.
Rechercher les cases à cocher en tant que telle
* Remarque: les valeurs sont à venir constituent la base de données
Je n'ai pas besoin de s'inquiéter vérifier si ce sont vérifiées, il suffit d'obtenir des valeurs, si ses une grande chaîne ou un tableau. explication complète est nécessaire avec les soltutions
beaucoup beaucoup apprécié
J'ai vraiment besoin de savoir comment obtenir les valeurs d'un tableau de case à cocher en utilisant la méthode POST en PHP.
Rechercher les cases à cocher en tant que telle
Code: [ Select ]
<input type="checkbox" name="branchsel[]" value="$data[BRANCH]">$data[BRANCH]<br>
* Remarque: les valeurs sont à venir constituent la base de données
Je n'ai pas besoin de s'inquiéter vérifier si ce sont vérifiées, il suffit d'obtenir des valeurs, si ses une grande chaîne ou un tableau. explication complète est nécessaire avec les soltutions
beaucoup beaucoup apprécié
- Anonymous
- Bot


- Inscription: 25 Feb 2008
- Messages: ?
- Loc: Ozzuland
- Status: Online
Juillet 28th, 2004, 9:44 am
- Cafu
- Student


- Inscription: Juil 15, 2004
- Messages: 97
- Status: Offline
Quote:
Je n'ai pas besoin de s'inquiéter vérifier si ce sont vérifiés
ils vont seulement pour envoyer les valeurs au serveur si elles sont cochées.
Supposons que vous ayez à ceci:
Code: [ Select ]
<input type="checkbox" name="fruit" value="apples">apples
<input type="checkbox" name="fruit" value="oranges">oranges
<input type="checkbox" name="fruit" value="peaches">peaches
<input type="checkbox" name="fruit" value="mangos">mangos
<input type="checkbox" name="fruit" value="oranges">oranges
<input type="checkbox" name="fruit" value="peaches">peaches
<input type="checkbox" name="fruit" value="mangos">mangos
- <input type="checkbox" name="fruit" value="apples">apples
- <input type="checkbox" name="fruit" value="oranges">oranges
- <input type="checkbox" name="fruit" value="peaches">peaches
- <input type="checkbox" name="fruit" value="mangos">mangos
Si vous cochez les pommes et les oranges,
$ HTTP_POST_VARS [ "fruit"] sera un tableau contenant deux valeurs: des pommes et des oranges.
- JackDaRippaZ
- Newbie


- Inscription: Juin 25, 2004
- Messages: 11
- Status: Offline
- Cafu
- Student


- Inscription: Juil 15, 2004
- Messages: 97
- Status: Offline
Est-ce une question?
Code: [ Select ]
<html>
<head>
<title>checkbox help</title>
</head>
<?
if (isset($HTTP_POST_VARS)) {
$fruit = $HTTP_POST_VARS["fruit"];
echo("Fruits chosen: " . count($fruit) . "<br><br>");
if (count($fruit)>0) {
echo("You chose the following fruits:<br>");
}
for ($i=0; $i<count($fruit); $i++) {
echo( ($i+1) . ") " . $fruit[$i] . "<br>");
}
}
?>
<body bgcolor="#ffffff">
<form method="post">
Choose a fruit:<br><br>
<input type="checkbox" name="fruit[]" value="apples">apples <br>
<input type="checkbox" name="fruit[]" value="oranges">oranges <br>
<input type="checkbox" name="fruit[]" value="peaches">peaches <br>
<input type="checkbox" name="fruit[]" value="mangos">mangos<br>
<input type="submit">
</form>
</body>
<html>
<head>
<title>checkbox help</title>
</head>
<?
if (isset($HTTP_POST_VARS)) {
$fruit = $HTTP_POST_VARS["fruit"];
echo("Fruits chosen: " . count($fruit) . "<br><br>");
if (count($fruit)>0) {
echo("You chose the following fruits:<br>");
}
for ($i=0; $i<count($fruit); $i++) {
echo( ($i+1) . ") " . $fruit[$i] . "<br>");
}
}
?>
<body bgcolor="#ffffff">
<form method="post">
Choose a fruit:<br><br>
<input type="checkbox" name="fruit[]" value="apples">apples <br>
<input type="checkbox" name="fruit[]" value="oranges">oranges <br>
<input type="checkbox" name="fruit[]" value="peaches">peaches <br>
<input type="checkbox" name="fruit[]" value="mangos">mangos<br>
<input type="submit">
</form>
</body>
<html>
- <html>
- <head>
- <title>checkbox help</title>
- </head>
- <?
- if (isset($HTTP_POST_VARS)) {
- $fruit = $HTTP_POST_VARS["fruit"];
- echo("Fruits chosen: " . count($fruit) . "<br><br>");
- if (count($fruit)>0) {
- echo("You chose the following fruits:<br>");
- }
- for ($i=0; $i<count($fruit); $i++) {
- echo( ($i+1) . ") " . $fruit[$i] . "<br>");
- }
- }
- ?>
- <body bgcolor="#ffffff">
- <form method="post">
- Choose a fruit:<br><br>
- <input type="checkbox" name="fruit[]" value="apples">apples <br>
- <input type="checkbox" name="fruit[]" value="oranges">oranges <br>
- <input type="checkbox" name="fruit[]" value="peaches">peaches <br>
- <input type="checkbox" name="fruit[]" value="mangos">mangos<br>
- <input type="submit">
- </form>
- </body>
- <html>
- drdrano
- Born


- Inscription: Mai 23, 2007
- Messages: 1
- Loc: La Crosse, WI, USA
- Status: Offline
Toutes mes excuses pour cette annonce à un fil vieux, mais ma recherche Google m'a amené ici et j'ai trouvé l'info ici, aide, bien que légèrement viciée et un peu daté. D'autres arrivent ici mai également besoin d'aide alors je vais apporter mon 2cents.
J'ai trouvé Cafus post ci-dessus pour être un bon tremplin place. $ HTTP_POST_VARS est maintenant obsolète et devrait être mis à jour pour la super globale $ _POST. J'ai mis à jour le code et un peu tordu comme je vous savoir comment le code gère cases à cocher. Mes notes sont inclus dans le code.
Larry Fundell
J'ai trouvé Cafus post ci-dessus pour être un bon tremplin place. $ HTTP_POST_VARS est maintenant obsolète et devrait être mis à jour pour la super globale $ _POST. J'ai mis à jour le code et un peu tordu comme je vous savoir comment le code gère cases à cocher. Mes notes sont inclus dans le code.
Code: [ Select ]
<!--
Instructive notes:
1. to use the if (isset($_POST['submit'])) construct, the submit button must have a name defined as 'submit'
2. if each of the checkboxes has been named with the same name (ie 'fruit') followed by a pair of square brackets '[]',
when the form is submitted, the $_POST superglobal will have a variable named $_POST['fruit'] that represents an
array containing array elements from only those checkboxes that have been checked.
3. count() returns the number of elements in an array. here it returns '0' if no checkboxes are checked. This could be
because $_POST['fruit'] is not set, or because $_POST['fruit'] represents an array that has been set but has no elements.
if we change the if statement to if (isset($_POST['fruit'])), the statements in the 'if' block are never executed,
so $_POST['fruit'] is not set and must evaluate to null. count() accurately returns '0' when its parameter is null.
4. the value of each element in the array $_POST['fruit'] is determined by the value attribute of each of the checkboxes.
5. note that in the absence of an 'action = "some_script.php" attribute in the form element, the browser reloads this script when the submit button is clicked.
-->
<html>
<head>
<title>checkbox help</title>
</head>
<?php
if (isset($_POST['submit'])) {
$fruit = $_POST["fruit"];
$how_many = count($fruit);
echo 'Fruits chosen: '.$how_many.'<br><br>';
if ($how_many>0) {
echo 'You chose the following fruits:<br>';
}
for ($i=0; $i<$how_many; $i++) {
echo ($i+1) . '- ' . $fruit[$i] . '<br>';
}
echo "<br><br>";
}
?>
<body bgcolor="#ffffff">
<form method="post">
Choose a fruit:<br><br>
<input type="checkbox" name="fruit[]" value="apples">apples <br>
<input type="checkbox" name="fruit[]" value="oranges">oranges <br>
<input type="checkbox" name="fruit[]" value="peaches">peaches <br>
<input type="checkbox" name="fruit[]" value="mangos">mangos<br>
<input type="submit" name = "submit">
</form>
</body>
<html>
Instructive notes:
1. to use the if (isset($_POST['submit'])) construct, the submit button must have a name defined as 'submit'
2. if each of the checkboxes has been named with the same name (ie 'fruit') followed by a pair of square brackets '[]',
when the form is submitted, the $_POST superglobal will have a variable named $_POST['fruit'] that represents an
array containing array elements from only those checkboxes that have been checked.
3. count() returns the number of elements in an array. here it returns '0' if no checkboxes are checked. This could be
because $_POST['fruit'] is not set, or because $_POST['fruit'] represents an array that has been set but has no elements.
if we change the if statement to if (isset($_POST['fruit'])), the statements in the 'if' block are never executed,
so $_POST['fruit'] is not set and must evaluate to null. count() accurately returns '0' when its parameter is null.
4. the value of each element in the array $_POST['fruit'] is determined by the value attribute of each of the checkboxes.
5. note that in the absence of an 'action = "some_script.php" attribute in the form element, the browser reloads this script when the submit button is clicked.
-->
<html>
<head>
<title>checkbox help</title>
</head>
<?php
if (isset($_POST['submit'])) {
$fruit = $_POST["fruit"];
$how_many = count($fruit);
echo 'Fruits chosen: '.$how_many.'<br><br>';
if ($how_many>0) {
echo 'You chose the following fruits:<br>';
}
for ($i=0; $i<$how_many; $i++) {
echo ($i+1) . '- ' . $fruit[$i] . '<br>';
}
echo "<br><br>";
}
?>
<body bgcolor="#ffffff">
<form method="post">
Choose a fruit:<br><br>
<input type="checkbox" name="fruit[]" value="apples">apples <br>
<input type="checkbox" name="fruit[]" value="oranges">oranges <br>
<input type="checkbox" name="fruit[]" value="peaches">peaches <br>
<input type="checkbox" name="fruit[]" value="mangos">mangos<br>
<input type="submit" name = "submit">
</form>
</body>
<html>
- <!--
- Instructive notes:
- 1. to use the if (isset($_POST['submit'])) construct, the submit button must have a name defined as 'submit'
- 2. if each of the checkboxes has been named with the same name (ie 'fruit') followed by a pair of square brackets '[]',
- when the form is submitted, the $_POST superglobal will have a variable named $_POST['fruit'] that represents an
- array containing array elements from only those checkboxes that have been checked.
- 3. count() returns the number of elements in an array. here it returns '0' if no checkboxes are checked. This could be
- because $_POST['fruit'] is not set, or because $_POST['fruit'] represents an array that has been set but has no elements.
- if we change the if statement to if (isset($_POST['fruit'])), the statements in the 'if' block are never executed,
- so $_POST['fruit'] is not set and must evaluate to null. count() accurately returns '0' when its parameter is null.
- 4. the value of each element in the array $_POST['fruit'] is determined by the value attribute of each of the checkboxes.
- 5. note that in the absence of an 'action = "some_script.php" attribute in the form element, the browser reloads this script when the submit button is clicked.
- -->
- <html>
- <head>
- <title>checkbox help</title>
- </head>
- <?php
- if (isset($_POST['submit'])) {
- $fruit = $_POST["fruit"];
- $how_many = count($fruit);
- echo 'Fruits chosen: '.$how_many.'<br><br>';
- if ($how_many>0) {
- echo 'You chose the following fruits:<br>';
- }
- for ($i=0; $i<$how_many; $i++) {
- echo ($i+1) . '- ' . $fruit[$i] . '<br>';
- }
- echo "<br><br>";
- }
- ?>
- <body bgcolor="#ffffff">
- <form method="post">
- Choose a fruit:<br><br>
- <input type="checkbox" name="fruit[]" value="apples">apples <br>
- <input type="checkbox" name="fruit[]" value="oranges">oranges <br>
- <input type="checkbox" name="fruit[]" value="peaches">peaches <br>
- <input type="checkbox" name="fruit[]" value="mangos">mangos<br>
- <input type="submit" name = "submit">
- </form>
- </body>
- <html>
Larry Fundell
- trekie8472
- Born


- Inscription: Juin 03, 2007
- Messages: 1
- Loc: Minneapolis, MN
- Status: Offline
- murcielagossi
- Proficient


- Inscription: Juil 28, 2006
- Messages: 457
- Status: Offline
Ou vous pourriez utiliser "foreach":
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
Le code du formulaire d'accompagnement seraient les suivantes:
Ce que ne précise pas assez --
http://www.kirupa.com/web/php_contact_form3.htm
PHP Code: [ Select ]
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
- foreach($_POST['check'] as $value) {
- $check_msg .= "Checked: $value\n";
- }
Le code du formulaire d'accompagnement seraient les suivantes:
Code: [ Select ]
<input type="checkbox" name="check[]" value="blue_color"> Blue<br>
<input type="checkbox" name="check[]" value="green_color"> Green<br>
<input type="checkbox" name="check[]" value="orange_color"> Orange<br>
<input type="checkbox" name="check[]" value="green_color"> Green<br>
<input type="checkbox" name="check[]" value="orange_color"> Orange<br>
- <input type="checkbox" name="check[]" value="blue_color"> Blue<br>
- <input type="checkbox" name="check[]" value="green_color"> Green<br>
- <input type="checkbox" name="check[]" value="orange_color"> Orange<br>
Ce que ne précise pas assez --
http://www.kirupa.com/web/php_contact_form3.htm

/* My Logic Is Undeniable */
- flann
- Novice


- Inscription: Juin 13, 2006
- Messages: 25
- Loc: Wisconsin
- Status: Offline
- ydajdaj
- Born


- Inscription: Mar 11, 2010
- Messages: 1
- Status: Offline
Je pourrais donner un coup de main? J'ai une table où les valeurs sakan...Je tiens à faire est de pouvoir par des cases à cocher ont la possibilité d'utiliser la même valeur pour plusieurs enregistrements.... Je suis une recrue.!
Par exemple j'ai une liste des élèves qui ont été le chargement d'une base de données, et ces élèves se voient attribuer une cote d'une autre base de données, comme parfois les cotes sont la même sélection est scores engorosso encore et encore....
case 4:
/ / ECRAN DE QUALIFICATION
print "input capturé face=arial <font size=3> </ font> <br>";
print "<table border=1>";
print "<borderColor TR = #bgColor = ffffff
Par exemple j'ai une liste des élèves qui ont été le chargement d'une base de données, et ces élèves se voient attribuer une cote d'une autre base de données, comme parfois les cotes sont la même sélection est scores engorosso encore et encore....
case 4:
/ / ECRAN DE QUALIFICATION
print "input capturé face=arial <font size=3> </ font> <br>";
print "<table border=1>";
print "<borderColor TR = #bgColor = ffffff