2012-09-19 112 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

相關問題