dqq46733 2013-12-27 02:42
浏览 27
已采纳

单击当前行中提交的隐藏输入的一个值

How to pass one value of the current row of multiple hidden input in PHP. I have the following code:

foreach($portfolio as $portfolio){
echo  "<tr class ='table-comments'>";
echo  "<td>".$portfolio['portfolio_title']."</td>";
echo  "<td class = 'comment-content'>".$portfolio['portfolio_client']."</td>";
echo  "<td><a target = '_blank' href = ".$portfolio['portfolio_link'].">".$portfolio['portfolio_link']."</a></td>";
echo  "<td>";
echo  "<input type='hidden' name='portfolio_id' value='" . $portfolio['portfolio_id'] . "' />";
echo "<input type = 'submit'  value = 'Edit'>";
echo "<input type = 'submit' value = 'Move to Trash' class = 'action-button'>";
echo  "</td>";
echo  "</tr>";
}

I also have submit button each row that triggers the form. When I click the submit button, it submits all the value of the row of the hidden input. I only want the clicked button row value.

URL is like this:

/portfolio?portfolio_id=1&portfolio_id=2&portfolio_id=3&portfolio_id=4 and so on

I only want

/portfolio?portfolio_id=3
  • 写回答

3条回答 默认 最新

  • doulangdang9986 2013-12-27 02:45
    关注

    Have a new form for each row...

    <form method="get">
    
    </form>
    

    Like this:

    foreach($portfolio as $portfolio){
    
        echo  "<tr class ='table-comments'>";
        echo  "<td>".$portfolio['portfolio_title']."</td>";
        echo  "<td class = 'comment-content'>".$portfolio['portfolio_client']."</td>";
        echo  "<td><a target = '_blank' href = ".$portfolio['portfolio_link'].">".$portfolio['portfolio_link']."</a></td>";
        echo  "<td>";
        echo '<form method="get">';
        echo  "<input type='hidden' name='portfolio_id' value='" . $portfolio['portfolio_id'] . "' />";
        echo "<input type = 'submit'  value = 'Edit'>";
        echo "<input type = 'submit' value = 'Move to Trash' class = 'action-button'>";
        echo "</form>";
        echo  "</td>";
        echo  "</tr>";
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?