Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. < input type="checkbox" name="Sound[]" value="item1" > item1
  2.  
  3. < input type="image" name="Submit" class="" alt="" src="images/contact1.png" border="0" >
  4.  
  5. <tr>
  6. <td valign="top">
  7. <label for="telephone">Telephone Number *</label>
  8. </td>
  9. <td valign="top">
  10. <input type="text" name="telephone" maxlength="30" size="30" style="margin-bottom: 10px;">
  11. </td>
  12. </tr>
  13.  
  14. <tr>
  15. <td colspan="2" style="text-align:center;">
  16. <input type="image" name="Contact" class="contactbutton" alt="" src="images/contact.jpg"/>
  17. </td>
  18. </tr>
  19.  
  20. you can do it with a form and send it to the page2.php. value will be stored in
  21. $_POST['S'] for the checkbox
  22.  
  23.  
  24. <form action="page2.php" method="post">
  25.  
  26. <input type="checkbox" name="S" value="item1" > item1
  27. <input type="SUBMIT" >
  28.  
  29. </form>
  30.  
  31. ------------------
  32. page2.php
  33.  
  34. echo($_POST['S']); // will be item1
  35.  
  36. $_SESSION array is better. to use it you need to put session_start(); at start of
  37. every page that will use your $_SESSION variable i.e
  38.  
  39. session_start();
  40.  
  41. if(isset($_POST['S'])){
  42. $_SESSION['h'] = $_POST['S'];
  43.  
  44. echo($_SESSION['h']); } //output value in checkbox
  45. ?>
  46. <html><body>
  47. <form method="post">
  48. <input type="checkbox" name="S" value="item1" > item1
  49. <input type="SUBMIT" value="item1" >
  50.  
  51.  
  52. Once this script is run you can accesS value in $_SESSION['h'] in other pages.
  53. the data will be deleted when you close browser.
  54.  
  55. ----------------------------------
  56.  
  57. page2.php
  58. <?php
  59. session_start();
  60.  
  61. if(isset($_SESSION['h'])){ //check if $_SESSION['h'] has been set a value
  62.  
  63. echo $_SESSION['h']; //output value stored in var
  64. }
  65. ?>
  66.  
  67. <?php
  68. session_start();
  69. // If postdata is received then redirect to next page
  70. if(isset($_POST['Sound'])) {
  71. $_SESSION['Sound'] = $_POST['Sound'];
  72. header('Location: http://www.example.com/page2.php');
  73. exit;
  74. }
  75. ?>
  76. <form method="post" action="page1.php">
  77. Sound? <input type="checkbox" name="Sound" value="item1"><br>
  78. <input type="submit">
  79. </form>
  80.  
  81. <?php
  82. session_start();
  83. // If postdata is received then redirect to next page
  84. if(isset($_POST['telephone']) && isset($_POST['email'])) {
  85. $_SESSION['telephone'] = $_POST['telephone'];
  86. $_SESSION['email'] = $_POST['email'];
  87. header('Location: http://www.example.com/page3.php');
  88. exit;
  89. }
  90. ?>
  91.  
  92. <form method="post" action="page2.php">
  93. <!-- If you want to output the previously saved data in a disabled item -->
  94. Sound? <input type="checkbox" name="Sound" value="item1" disabled="disabled" <?php if($_SESSION['Sound'] == 'Yes') echo('checked="checked"'); ?>>
  95.  
  96. Telephone: <input type="text" name="telephone" value=""><br>
  97. Email: <input type="email" name="email" value=""><br>
  98. <input type="submit">
  99. </form>
  100.  
  101. <?php session_start();
  102. if (!isset($_SESSION['user'])) {$_SESSION['user']=rand(10,700);}
  103. if (isset($_POST['user'])) {$id=$_POST['user'];} else {$id=$_SESSION['user'];}
  104. ?>
  105.  
  106. <form action="" method="post">
  107. Sound 1:<input name="cb1" type="checkbox" value="sound1"><br>
  108. Sound 2:<input name="cb2" type="checkbox" value="sound2"><br>
  109. Sound 3:<input name="cb3" type="checkbox" value="sound3"><br>
  110. <input type="submit" name="submit" value="submit"><br><br>
  111.  
  112. <?php
  113.  
  114.  
  115. if (isset($_POST['submit']) && $_POST!=="") {
  116. foreach($_POST as $key => $value) {
  117. $_SESSION['visitor']['sounds'][$id]=array(
  118. 'selects'=>$_POST['cb1'].",".$_POST['cb2'].",".$_POST['cb3']
  119. );
  120. };
  121.  
  122. echo "For user ID:".$id." We echo the comma delimited stored SESSION array: ".$_SESSION['visitor']['sounds'][$id] ['selects'];
  123. echo "<br><br>";
  124. // Option 2 Explodes the comma delimited ['selects'] field to handle each choice seperately
  125.  
  126. $choice = explode(",",$_SESSION['visitor']['sounds'][$id] ['selects']);
  127.  
  128. echo "For an alternative, we EXPLODE the stored 'selects' field of the SESSION ARRAY and can then echo each out seperately"."<br><br>";
  129.  
  130. echo "User ".$id." Option 1 value was: ".$choice[0]."<br>";
  131. echo "User ".$id." Option 2 value was: ".$choice[1]."<br>";
  132. echo "User ".$id." Option 3 value was: ".$choice[2]."<br>";
  133.  
  134. echo "<br><br>";
  135.  
  136. echo "A last example we loop through the EXPLODED values and echo only those that were selected (ie: had a value)"."<br>";
  137.  
  138. foreach ($choice as $key => $value ) { if ($value!=="") {echo "Selection: ".$value."<br>";} }
  139.  
  140. }
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement