Desperate-gettin à cocher valeurs POST (PHP)

  • JackDaRippaZ
  • Newbie
  • Newbie
  • No Avatar
  • Inscription: Juin 25, 2004
  • Messages: 11
  • Status: Offline

Message Juillet 28th, 2004, 9:44 am

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

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
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Juillet 28th, 2004, 9:44 am

  • Cafu
  • Student
  • Student
  • No Avatar
  • Inscription: Juil 15, 2004
  • Messages: 97
  • Status: Offline

Message Juillet 28th, 2004, 10:02 am

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
  1. <input type="checkbox" name="fruit" value="apples">apples
  2. <input type="checkbox" name="fruit" value="oranges">oranges
  3. <input type="checkbox" name="fruit" value="peaches">peaches
  4. <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
  • Newbie
  • No Avatar
  • Inscription: Juin 25, 2004
  • Messages: 11
  • Status: Offline

Message Juillet 28th, 2004, 4:15 pm

yeah i nah besoin pour obtenir les valeurs d'une case à cocher array

Je sais comment les mettre à une autre page, mais de les mettre dans son / leur tri dans un tableau ou par l'intermédiaire du tableau de tri

s'il vous plaît
  • Cafu
  • Student
  • Student
  • No Avatar
  • Inscription: Juil 15, 2004
  • Messages: 97
  • Status: Offline

Message Juillet 28th, 2004, 6:09 pm

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>
  1. <html>
  2. <head>
  3. <title>checkbox help</title>
  4. </head>
  5. <?
  6. if (isset($HTTP_POST_VARS)) {
  7.     $fruit = $HTTP_POST_VARS["fruit"];
  8.     echo("Fruits chosen: " . count($fruit) . "<br><br>");
  9.     if (count($fruit)>0) {
  10.         echo("You chose the following fruits:<br>");
  11.     }
  12.     for ($i=0; $i<count($fruit); $i++) {
  13.         echo( ($i+1) . ") " . $fruit[$i] . "<br>");
  14.     }
  15. }
  16. ?>
  17. <body bgcolor="#ffffff">
  18. <form method="post">
  19. Choose a fruit:<br><br>
  20. <input type="checkbox" name="fruit[]" value="apples">apples <br>
  21. <input type="checkbox" name="fruit[]" value="oranges">oranges <br>
  22. <input type="checkbox" name="fruit[]" value="peaches">peaches <br>
  23. <input type="checkbox" name="fruit[]" value="mangos">mangos<br>
  24. <input type="submit">
  25. </form>
  26. </body>
  27. <html>
  • drdrano
  • Born
  • Born
  • No Avatar
  • Inscription: Mai 23, 2007
  • Messages: 1
  • Loc: La Crosse, WI, USA
  • Status: Offline

Message Mai 23rd, 2007, 7:50 am

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.

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>
  1. <!-- 
  2. Instructive notes:
  3.     1. to use the   if (isset($_POST['submit']))  construct, the submit button must have a name defined as 'submit'
  4.     2. if each of the checkboxes has been named with the same name (ie 'fruit') followed by a pair of square brackets '[]',
  5. when the form is submitted, the $_POST superglobal will have a variable named $_POST['fruit'] that represents an
  6. array containing array elements from only those checkboxes that have been checked.
  7.     3. count() returns the number of elements in an array. here it returns '0' if no checkboxes are checked. This could be 
  8. because $_POST['fruit'] is not set, or because $_POST['fruit'] represents an array that has been set but has no elements.
  9. if we change the if statement to  if (isset($_POST['fruit'])), the statements in the 'if' block are never executed, 
  10. so $_POST['fruit'] is not set and must evaluate to null. count() accurately returns '0' when its parameter is null.
  11.     4. the value of each element in the array $_POST['fruit'] is determined by the value attribute of each of the checkboxes.
  12.     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.
  13. -->
  14. <html>
  15. <head>
  16. <title>checkbox help</title>
  17. </head>
  18. <?php
  19. if (isset($_POST['submit'])) {
  20.     $fruit = $_POST["fruit"];
  21.     $how_many = count($fruit);
  22.     echo 'Fruits chosen: '.$how_many.'<br><br>';
  23.     if ($how_many>0) {
  24.         echo 'You chose the following fruits:<br>';
  25.     }
  26.     for ($i=0; $i<$how_many; $i++) {
  27.         echo ($i+1) . '- ' . $fruit[$i] . '<br>';
  28.     }
  29.         echo "<br><br>";
  30. }
  31. ?>
  32. <body bgcolor="#ffffff">
  33. <form method="post">
  34. Choose a fruit:<br><br>
  35. <input type="checkbox" name="fruit[]" value="apples">apples <br>
  36. <input type="checkbox" name="fruit[]" value="oranges">oranges <br>
  37. <input type="checkbox" name="fruit[]" value="peaches">peaches <br>
  38. <input type="checkbox" name="fruit[]" value="mangos">mangos<br>
  39. <input type="submit" name = "submit">
  40. </form>
  41. </body>
  42. <html>


Larry Fundell
  • trekie8472
  • Born
  • Born
  • No Avatar
  • Inscription: Juin 03, 2007
  • Messages: 1
  • Loc: Minneapolis, MN
  • Status: Offline

Message Juin 3rd, 2007, 9:27 pm

Merci pour cette mise à jour! C'est exactement ce que je cherchais, et ce un hasard qu'il a été envoyé par quelqu'un de ma ville natale de La Crosse.
  • murcielagossi
  • Proficient
  • Proficient
  • Avatar de l’utilisateur
  • Inscription: Juil 28, 2006
  • Messages: 457
  • Status: Offline

Message Juin 5th, 2007, 3:11 pm

Ou vous pourriez utiliser "foreach":

PHP Code: [ Select ]
 
foreach($_POST['check']  as  $value)  {
 
$check_msg .= "Checked: $value\n";
 
}
 
 
  1.  
  2. foreach($_POST['check']  as  $value)  {
  3.  
  4. $check_msg .= "Checked: $value\n";
  5.  
  6. }
  7.  
  8.  


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>
  1. <input type="checkbox" name="check[]" value="blue_color"> Blue<br>
  2. <input type="checkbox" name="check[]" value="green_color"> Green<br>
  3. <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
Image
/* My Logic Is Undeniable */
  • flann
  • Novice
  • Novice
  • No Avatar
  • Inscription: Juin 13, 2006
  • Messages: 25
  • Loc: Wisconsin
  • Status: Offline

Message Octobre 29th, 2007, 10:41 am

il est de toute façon à obtenir toutes les cases à cocher dans le cadre d'un poste, même ceux qui ne sont pas vérifiés? Je suis moi aussi de La Crosse :) .
  • ydajdaj
  • Born
  • Born
  • No Avatar
  • Inscription: Mar 11, 2010
  • Messages: 1
  • Status: Offline

Message Mars 11th, 2010, 12:38 pm

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