Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- < input type="checkbox" name="Sound[]" value="item1" > item1
- < input type="image" name="Submit" class="" alt="" src="images/contact1.png" border="0" >
- <tr>
- <td valign="top">
- <label for="telephone">Telephone Number *</label>
- </td>
- <td valign="top">
- <input type="text" name="telephone" maxlength="30" size="30" style="margin-bottom: 10px;">
- </td>
- </tr>
- <tr>
- <td colspan="2" style="text-align:center;">
- <input type="image" name="Contact" class="contactbutton" alt="" src="images/contact.jpg"/>
- </td>
- </tr>
- you can do it with a form and send it to the page2.php. value will be stored in
- $_POST['S'] for the checkbox
- <form action="page2.php" method="post">
- <input type="checkbox" name="S" value="item1" > item1
- <input type="SUBMIT" >
- </form>
- ------------------
- page2.php
- echo($_POST['S']); // will be item1
- $_SESSION array is better. to use it you need to put session_start(); at start of
- every page that will use your $_SESSION variable i.e
- session_start();
- if(isset($_POST['S'])){
- $_SESSION['h'] = $_POST['S'];
- echo($_SESSION['h']); } //output value in checkbox
- ?>
- <html><body>
- <form method="post">
- <input type="checkbox" name="S" value="item1" > item1
- <input type="SUBMIT" value="item1" >
- Once this script is run you can accesS value in $_SESSION['h'] in other pages.
- the data will be deleted when you close browser.
- ----------------------------------
- page2.php
- <?php
- session_start();
- if(isset($_SESSION['h'])){ //check if $_SESSION['h'] has been set a value
- echo $_SESSION['h']; //output value stored in var
- }
- ?>
- <?php
- session_start();
- // If postdata is received then redirect to next page
- if(isset($_POST['Sound'])) {
- $_SESSION['Sound'] = $_POST['Sound'];
- header('Location: http://www.example.com/page2.php');
- exit;
- }
- ?>
- <form method="post" action="page1.php">
- Sound? <input type="checkbox" name="Sound" value="item1"><br>
- <input type="submit">
- </form>
- <?php
- session_start();
- // If postdata is received then redirect to next page
- if(isset($_POST['telephone']) && isset($_POST['email'])) {
- $_SESSION['telephone'] = $_POST['telephone'];
- $_SESSION['email'] = $_POST['email'];
- header('Location: http://www.example.com/page3.php');
- exit;
- }
- ?>
- <form method="post" action="page2.php">
- <!-- If you want to output the previously saved data in a disabled item -->
- Sound? <input type="checkbox" name="Sound" value="item1" disabled="disabled" <?php if($_SESSION['Sound'] == 'Yes') echo('checked="checked"'); ?>>
- Telephone: <input type="text" name="telephone" value=""><br>
- Email: <input type="email" name="email" value=""><br>
- <input type="submit">
- </form>
- <?php session_start();
- if (!isset($_SESSION['user'])) {$_SESSION['user']=rand(10,700);}
- if (isset($_POST['user'])) {$id=$_POST['user'];} else {$id=$_SESSION['user'];}
- ?>
- <form action="" method="post">
- Sound 1:<input name="cb1" type="checkbox" value="sound1"><br>
- Sound 2:<input name="cb2" type="checkbox" value="sound2"><br>
- Sound 3:<input name="cb3" type="checkbox" value="sound3"><br>
- <input type="submit" name="submit" value="submit"><br><br>
- <?php
- if (isset($_POST['submit']) && $_POST!=="") {
- foreach($_POST as $key => $value) {
- $_SESSION['visitor']['sounds'][$id]=array(
- 'selects'=>$_POST['cb1'].",".$_POST['cb2'].",".$_POST['cb3']
- );
- };
- echo "For user ID:".$id." We echo the comma delimited stored SESSION array: ".$_SESSION['visitor']['sounds'][$id] ['selects'];
- echo "<br><br>";
- // Option 2 Explodes the comma delimited ['selects'] field to handle each choice seperately
- $choice = explode(",",$_SESSION['visitor']['sounds'][$id] ['selects']);
- echo "For an alternative, we EXPLODE the stored 'selects' field of the SESSION ARRAY and can then echo each out seperately"."<br><br>";
- echo "User ".$id." Option 1 value was: ".$choice[0]."<br>";
- echo "User ".$id." Option 2 value was: ".$choice[1]."<br>";
- echo "User ".$id." Option 3 value was: ".$choice[2]."<br>";
- echo "<br><br>";
- echo "A last example we loop through the EXPLODED values and echo only those that were selected (ie: had a value)"."<br>";
- foreach ($choice as $key => $value ) { if ($value!=="") {echo "Selection: ".$value."<br>";} }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement