0

这种形式在一个形式中有多个 tbody。每个 tbody 都包含具有“唯一”值的“隐藏”字段。但是,发送此表单时,它只发送最后一个“pouzivatel_id”值。

例如

我想执行“pouzivatel_id”=4,但表单发送“pouzivatel_id”=“1”

如果不使用多个表单,我将如何解决这个问题?

<form method="post" action="lib/action/admin.post.php">
<table>
    <thead>
        <tr>
            <th>Osobné číslo</th>
            <th>Prezývka</th>
            <th>Meno</th>
            <th>Priezvisko</th>
            <th>Operácie</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>00000000004</td>
            <td>user4</td>
            <td>user</td>
            <td>user</td>
            <td>
                <input type="hidden" name="pouzivatel_id" value="4"/>
                <button type="submit" name="ziadatel-schvalit" class="tlacidlo zelena">Schváliť</button>
                <button type="submit" name="ziadatel-zmazat" class="tlacidlo cervena">Zamietnuť</button>
            </td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td>00000000003</td>
            <td>user3</td>
            <td>user</td>
            <td>user</td>
            <td>
                <input type="hidden" name="pouzivatel_id" value="3"/>
                <button type="submit" name="ziadatel-schvalit" class="tlacidlo zelena">Schváliť</button>
                <button type="submit" name="ziadatel-zmazat" class="tlacidlo cervena">Zamietnuť</button>
            </td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td>00000000002</td>
            <td>user2</td>
            <td>user</td>
            <td>user</td>
            <td>
                <input type="hidden" name="pouzivatel_id" value="2"/>
                <button type="submit" name="ziadatel-schvalit" class="tlacidlo zelena">Schváliť</button>
                <button type="submit" name="ziadatel-zmazat" class="tlacidlo cervena">Zamietnuť</button>
            </td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td>00000000001</td>
            <td>user1</td>
            <td>user</td>
            <td>user</td>
            <td>
                <input type="hidden" name="pouzivatel_id" value="1"/>
                <button type="submit" name="ziadatel-schvalit" class="tlacidlo zelena">Schváliť</button>
                <button type="submit" name="ziadatel-zmazat" class="tlacidlo cervena">Zamietnuť</button>
            </td>
        </tr>
    </tbody>
</table>

4

1 回答 1

1

您可以为每个提交按钮使用不同的名称。如果按下提交按钮,则只有这个提交按钮会发送到您的 PHP 脚本。在您的 PHP 脚本中,您检查按下了哪个按钮。

示例 HTML 代码:

<input type="hidden" name="pouzivatel_id[]" value="2"/>
<button type="submit" name="ziadatel-schvalit_2" class="tlacidlo zelena">Schváliť</button>
<button type="submit" name="ziadatel-zmazat_2" class="tlacidlo cervena">Zamietnuť</button>
<input type="hidden" name="pouzivatel_id[]" value="1"/>
<button type="submit" name="ziadatel-schvalit_1" class="tlacidlo zelena">Schváliť</button>
<button type="submit" name="ziadatel-zmazat_1" class="tlacidlo cervena">Zamietnuť</button>

示例 PHP 代码:

<?PHP
foreach($_POST['pouzivatel_id'] as $id)
{
    if(isset($_POST['ziadatel-schvalit_' . $id]))
    {
        //Schváliť
    }
    elseif(isset($_POST['ziadatel-zmazat_' . $id]))
    {
        //Zamietnuť
    }
}
?>
于 2013-03-10T21:41:34.840 回答