因为<form>不能在<tr>内,所以我不能为每一行分配窗体。最后我创造了一个

<form>
<table>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
</table>
</form>

所以,当我提交数据时,它似乎提交了每个输入,我如何才能只发送一个特定的行?谢谢

最佳答案

由于表单发送所有值(由于使用<button>),您可以为每一行分配一个对应于该行的键。然后在文本框中使用它。注意:Textbox值必须是一个数组结构,这样就可以使用submit update中的特定键(类似于过滤)。举个例子:

<?php

if(isset($_POST['update'])) {
    $product_key = $_POST['update'];
    $product_name = $_POST['my_product_name'][$product_key];
    echo $product_name;
    // this should correspond to that same textbox row that you selected
}

?>

<form method="POST" action="">
    <table>
        <tr>
            <td><input type="text" name="my_product_name[1]"></td>
            <td><button name="update" type="submit" value="1">Update</button></td>
        </tr>
        <tr>
            <td><input type="text" name="my_product_name[2]"></td>
            <td><button name="update" type="submit" value="2">Update</button></td>
        </tr>
    </table>
</form>

08-05 21:34
查看更多