SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form don't send value with URL

    the html form below sends the URL value to the script to open that URL in popup window it sends the right value written "vote.php?id=$row[qid]&" but i want it to send that value + the value of the radio button R1 to b like that as example "vote.php?id=$row[qid]&R1=r1"
    Code JavaScript:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Idea by:  Nic Wolfe (Nic@TimelapseProductions.com) -->
    <!-- Web URL:  [url]http://fineline.xs.mw[/url] -->
     
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! [url]http://javascript.internet.com[/url] -->
     
    <!-- Begin
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
     
    eval("page" + id + " = window.open(URL + un, '" + id + "', 'toolbar=1,
    scrollbars=1,location=1,statusbar=0,menubar=0,
    resizable=0,width=750,height=200,left = 301,top = 332');");
    }
    // End -->
    </script>

    Code HTML4Strict:
    <form method="POST" name="vote" action="" onsubmit="javascript:popUp('<?php echo "vote.php?id=$row[qid]&"; ?>')">
    	<div align="center">
    		<table border="0" width="231" cellspacing="1" id="table1">
    			<tr>
    				<td colspan="2"><?php echo $row[ques]; ?></td>
    			</tr>
    			<tr>
    				<td width="23"><input type="radio" value="r1" name="R1"></td>
    				<td width="201"><?php echo $row[a1]; ?></td>
    			</tr>
    			<tr>
    				<td width="23"><input type="radio" value="r2" name="R1"></td>
    				<td width="201"><?php echo $row[a2]; ?></td>
    			</tr>
    			<tr>
    				<td width="23"><input type="radio" value="r3" name="R1"></td>
    				<td width="201"><?php echo $row[a3]; ?></td>
    			</tr>
    			<tr>
    				<td width="23"><input type="radio" value="r4" name="R1"></td>
    				<td width="201"><?php echo $row[a4]; ?></td>
    			</tr>
    			<tr>
    				<td colspan="2">
    				<p align="center"><input type="submit" value="vote" name="B1"></td>
    			</tr>
    		</table>
    	</div>
    </form>

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your really making it more difficult on yourself, you really don't need to pass anything along the url.

    Here is an example, copy, paste and save to a file as vote.php, it simply calls itself for this example.

    HTML Code:
    <?php 
    
    # Sample voting script by ngcomputing.com
    # modify as you please.
    
    
    if($_POST['button'] <> "") {
    
      echo "The Question ID Is : " . $_POST['qid'] . "<br><br>";
      
      echo "The Answer Selected Was : " . $_POST['RadioGroup1']; 
    
    }
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Vote Test</title>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="vote.php">
    <input type=hidden name=qid value=101 />
      <p>
        <label>
          <input name="RadioGroup1" type="radio"  value="1" checked="checked" />
          Answer #1</label>
        <br />
        <label>
          <input type="radio" name="RadioGroup1" value="2"  />
          Answer #2</label>
        <br />
        <label>
          <input type="radio" name="RadioGroup1" value="3"  />
          Answer #3</label>
      </p>
      <p>&nbsp;</p>
      <p>
        <label>
        <input type="submit" name="button" id="button" value="Click To Display Answer" />
        </label>
        <br />
      </p>
    </form>
    </body>
    </html>
    In your html you can do this ...

    Code:
    <form method="POST" name="vote" action="" onsubmit="javascript:popUp('vote.php')"> <input type=hidden name=qid value="<?php echo $qid;?>" > <div align="center"> <table border="0" width="231" cellspacing="1" id="table1"> <tr> <td colspan="2"><?php echo $row[ques]; ?></td> </tr> <tr> <td width="23"><input type="radio" value=1 name="R1"></td> <td width="201"><?php echo $row[a1]; ?></td> </tr> <tr> <td width="23"><input type="radio" value=2 name="R1"></td> <td width="201"><?php echo $row[a2]; ?></td> </tr> <tr> <td width="23"><input type="radio" value=3 name="R1"></td> <td width="201"><?php echo $row[a3]; ?></td> </tr> <tr> <td width="23"><input type="radio" value=4 name="R1"></td> <td width="201"><?php echo $row[a4]; ?></td> </tr> <tr> <td colspan="2"> <p align="center"><input type="submit" value="vote" name="B1"></td> </tr> </table> </div> </form>
    Then in your vote.php script just do something like :

    $qid = (int) $_POST['qid'];
    $answer = (int) $_POST['R1'];

    (I like to cast numeric answers to ints in order to weed out someone trying to pass a mysql query).
    intragenesis, llc professional web & graphic design


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •