简体   繁体   English

将单选按钮值传递给表单提交

[英]Pass Radio Button Value to Form Submit

I wonder whether someone may be able to hep me please. 我想知道是否有人可以帮我。

I've put together this page which allows the user to view the records saved in their account. 我把这个页面放在一起,使用户可以查看保存在其帐户中的记录。

What I'm now trying to do is add the functionality whereby the user can select a radio button, click on the 'Location Details' icon, and they are taken to the 'Details Page' pertinent to the record which they have selected the radio button against. 我现在想做的是添加功能,用户可以选择单选按钮,单击“位置详细信息”图标,然后将其带到与他们选择了广播的记录相关的“详细信息页面”反对。

The problem I'm having is that no matter which radio button I select, when I click on the icon, I'm always taken to the 'Details Page' for the last record. 我遇到的问题是,无论我选择哪个单选按钮,单击图标时,我总是被带到“详细信息页面”以获取最后一条记录。 (* NB * For the purpose of this post I've taken the 'submit' action away from the button. ) (* 注意 *出于本文的目的,我已经从按钮上采取了“提交”操作。

The code below creates the table and 'Location Details' icon 下面的代码创建表格和“位置详细信息”图标

 <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>

Because I intend to have several submit buttons within one form, I've created the following 'locationsaction.php' script which you will see is called in the above script. 因为我打算在一种表单中包含多个提交按钮,所以我创建了以下“ 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);
}
?>

I've been working on this for several days now and have tried several tutorials, but I just can't seem to get this to work. 我已经为此工作了几天,并尝试了一些教程,但是似乎无法使它起作用。

I just wondered whether someone may be able to take a look at this please and offer some guidance on how I can pass the correct radio button value through the 'submit action. 我只是想知道是否有人可以看一下这个问题,并提供一些指导,说明如何通过“提交”操作传递正确的单选按钮值。

Many thanks and kind regards 非常感谢和问候

This is your current form: 这是您目前的表格:

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

Your table is not in your form at all; 您的表格完全没有表格; when you click on the submit button, it will only send details of inputs that are between the <form> tags. 当您单击提交按钮时,它将仅发送<form>标记之间的输入的详细信息。

If you move the <form action tag right to the top of the page, it should work. 如果将<form action标签移动到页面顶部的右边,它应该可以工作。

I believe your opening form tag should be above the most upper input type field. 我相信您的开始表单标签应位于最上方的输入类型字段上方。 I'm not entirely sure but that's the first thing I noticed. 我不确定,但这是我注意到的第一件事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM