2012-09-19 63 views
2

我想知道是否有人能够帮助我。将单选按钮值传递给表单提交

我把放在一起的this页面允许用户查看保存在他们账户中的记录。

我现在要做的是添加用户可以选择一个单选按钮的功能,单击“位置详细信息”图标,然后将它们带到与“记录”相关的“详细信息页”已经选择了反对的单选按钮。

我遇到的问题是,无论选择哪个单选按钮,当我单击图标时,我都会被带到最后一条记录的“详细信息页面”。 (*NB *对于这个职位,我已经采取了“提交”行动远离按钮的用途。

下面的代码创建表和“详细地点”图标

<table id="theTable" width="835" class="sortable-onload-zebra no-arrow rowstyle-alt colstyle-alt paginate-20 max-pages-20 paginationcallback-callbackTest-calculateTotalRating paginationcallback-callbackTest-displayTextInfo sortcompletecallback-callbackTest-calculateTotalRating"> 
       <thead> 
       <tr> 
        <th width="60" bgcolor="#ff8401">Select</th> 
        <th width="150" class="sortable-text" bgcolor="#ff8401">Location</th> 
        <th width="300" class="sortable-text" bgcolor="#ff8401">Address</th> 
        <th width="30" class="sortable-text" bgcolor="#ff8401">Finds</th> 
       </tr> 
       </thead> 
       <tbody> 
       <?php 
        mysql_data_seek($result, 0); 
        while ($row = mysql_fetch_array($result)) { 
         /* display row for each user */ 

       ?> 
       <tr height="80px"> 
        <td style="text-align: center"><input type="radio" id="lid" name="lid" value=<?php echo $row['locationid'];?> /></td> 
        <td style="text-align: left"><strong><?php echo $row['locationname'];?></strong></td> 
        <td style="text-align: center"><?php echo $row['returnedaddress'];?></td> 
        <td style="text-align: center"><strong><em><?php echo $row['totalfinds'];?></em></strong></td> 

      </tr> 

       <?php 
         } 
        } else { 
         echo "<tr> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td>          
          </tr> 
          <tr> 
           <td colspan='5'><div align='center'><strong>No locations have been added yet. <a href='addlocation.php'>Click here</a> to add one.</strong></div></td> 
          </tr> 
          <tr> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
          </tr>"; 

} 

?> 
       <form action='locationsaction.php'> 
       <input type='submit' class='detailsButton' name='type' value='Details' alt='Location Details' title='Location Details' style='margin-right:10px' /> 
       </form> 
      </tbody> 
      </table> 

因为我打算在一个表单中有几个提交按钮,所以我创建了以下'locationsaction.php'脚本,您将在上面的脚本中调用您将看到的脚本。

<?php 
session_start(); 
$_SESSION['lid'] = $_POST['lid']; 
if (isset($_POST['type'])) { 
    $urls = array(
     'Details' => 'locationdetails.php', 
     'Add Finds' => 'addfinds.php', 
     'Images' => 'addimages.php', 
     'View Finds' => 'locationfinds.php' 
    ); 
    $url = $urls[$_POST['type']]; 
    header("Location: " . $url); 
} 
?> 

我一直在这工作了好几天,并尝试了几个教程,但我似乎无法得到这个工作。

我只是想知道是否有人能够看看这个请提供一些指导,我如何通过'提交行动传递正确的单选按钮值。

许多的感谢和亲切的问候

回答

2

这是你目前的形式:

<form action='locationsaction.php'> 
<input type='submit' class='detailsButton' name='type' value='Details' alt='Location Details' title='Location Details' style='margin-right:10px' /> 
</form> 

你的表是不是在你的形式在所有;当您点击提交按钮时,它只会发送介于<form>标签之间的输入详细信息。

如果将<form action标记右移到页面的顶部,它应该可以工作。

+0

嗨@andrewsi,非常感谢您花时间回复我的帖子。一旦我发布了这篇文章,我偶然发现了另一个基本上证实了你的说法的教程。亲切的问候 – IRHM

2

我相信你的开放表格标签应该高于最高输入类型字段。我不完全确定,但那是我注意到的第一件事。

+0

嗨Glenn Plas,谢谢你看看花时间回复。正如我在对@andrewsi的评论中所说的那样,只要我发布了这篇文章,我就找到了一个教程,重申了你的意思。亲切的问候 – IRHM

+0

我注意到我们相隔17秒。 Tx确认解决方案! –

+0

没问题,谢谢你的时间。亲切的问候 – IRHM