如何$ _POST没有点击按钮?

Vin*_*gno 5 html php forms jquery

之前,我有一个带有单选按钮的表单,当然,按下提交时它会在单选按钮中提交值.

但如果我不再需要收音机按钮,我该怎么办呢?当按表格单元格或行时会自动将值提交到下一页而不提交按钮?

<form method="post" action="billing.php">
    <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
        <tr>
            <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?>  value="LBC"></td>
            <td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td>
            <td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p>
                <div id='price'> Additional ?250 </div></td>

        </tr>
        <tr>
            <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?>  value="PickUp"></td>
            <td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
            <td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p>
                <div id='price'> Free!! </div></td>
        </tr>
    </table>
</form>
Run Code Online (Sandbox Code Playgroud)

如何在不使用提交按钮或单选按钮的情况下进行提交,因为当我按下行时,它会将值提交到下一页,然后我转到下一页.

谢谢

编辑.

<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='centerdown'>
    <tr>
        <td><input type="radio"  name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?>  value="BPI"></td>
        <td><img src="../paymentoptions/BPI.jpg"></td>
        <td><p>Pay by BPI bank deposit (we need confirmation of payment through email.)<p></td>
    </tr>

    <tr>
        <td><input type="radio"  name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?>  value="PickUp"></td>
        <td><img src="../paymentoptions/Pick-up.jpg"></td>
        <td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

Kev*_*vin 2

只需使用行来提交即可。考虑这个标记:

\n\n
<form method="post" action="billing.php">\n    <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id=\'center\'>\n        <tr class="row_submit">\n               <!-- ^^ simple class assignment -->\n            <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?>  value="LBC"></td>\n            <td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td>\n            <td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p>\n                <div id=\'price\'> Additional \xe2\x82\xb1250 </div></td>\n\n        </tr>\n        <tr class="row_submit">\n            <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?>  value="PickUp"></td>\n            <td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>\n            <td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p>\n                <div id=\'price\'> Free!! </div></td>\n        </tr>\n    </table>\n</form>\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后在你的JS上:

\n\n
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>\n<script type="text/javascript">\n$(document).ready(function(){\n    $(\'tr.row_submit\').on(\'click\', function(e){\n        $(\'form\').submit();\n    });\n});\n</script>\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后在 PHP 上:

\n\n
$info_table = array(\n    \'LBC\' => array(\n        \'price\' => 250,\n        \'payment\' => \'BPI\',\n    ),\n    \'PickUp\' => array(\n        \'price\' => 0,\n        \'payment\' => \'\',\n    ),\n);\n\nif(isset($_POST[\'carrier\'])){\n    echo $_POST[\'carrier\'];\n    $price = $info_table[$_POST[\'carrier\']][\'price\'];\n    $payment = $info_table[$_POST[\'carrier\']][\'payment\'];\n    echo \'<br/>\' . $price . \'<br/>\';\n    echo $payment;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

  • @DaOgre,如果您想准备声明,那么当然,无论如何,这是另一个话题,它会太长,但我当然理解您的担忧 (2认同)