我如何在PHP中使用href传递复选框值?

时间:2015-08-13 05:15:37

标签: php

我想使用href链接进行多次删除,我该怎么办?

此代码生成以下错误。

Notice: Undefined index: action in
C:\xampp\htdocs\montu\montu\multiple.php on line 32

Warning: implode() [function.implode]: Invalid arguments passed in
C:\xampp\htdocs\montu\montu\multiple.php on line 32



<body>
    <form method="post" action="<?php $_PHP_SELF ?>">
        <table>
            <tr>
                <td>
                    <input type="checkbox" name="action[]" value="1">1
                </td>
                <td>
                    <input type="checkbox" name="action[]" value="2">2
                </td>
            </tr>
            <tr>
                <td>
                    <a href="?id">Click Me..</a>
                </td>
            </tr>

        </table>
    </form>

<?php 
    if(isset($_REQUEST['id']))
    {
        $action=implode(',',$_REQUEST['action']);//convert array value to string values
        echo $action;
    }
?>

1 个答案:

答案 0 :(得分:2)

请尝试这样..

<?php 
    if(isset($_POST['action']))
    {
        //print_r($_REQUEST);
        $action=implode(',',$_REQUEST['action']);//convert array value to string values
        echo $action;
    }
?>
<body>
    <form name="frm" id="frm" method="post">
        <table>
            <tr>
                <td>
                    <input type="checkbox" name="action[]" value="1">1
                </td>
                <td>
                    <input type="checkbox" name="action[]" value="2">2
                </td>
            </tr>
            <tr>
                <td>
                    <a onclick="document.forms['frm'].submit()" href="#">Click Me..</a>
                </td>
            </tr>

        </table>
    </form>