Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to $_POST without clicking button?

Before, i have a form that has a radio button and of course, it submits the value in the radio button when pressing submit.

but how do i do it if i dont want radio buttons anymore? When pressing the table cell or row will automatically submit the value to the next page without the submit button?

<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>

how do i make it submit without using submit button or the radio button, for when i press the row, it submits the value to the next page and i go to the next page.

thank you

EDIT.

<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>
like image 434
Vince Agno Avatar asked Oct 21 '22 01:10

Vince Agno


1 Answers

Just use the rows to submit it. Consider this markup:

<form method="post" action="billing.php">
    <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
        <tr class="row_submit">
               <!-- ^^ simple class assignment -->
            <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 class="row_submit">
            <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>

Then on your JS:

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

Then on PHP:

$info_table = array(
    'LBC' => array(
        'price' => 250,
        'payment' => 'BPI',
    ),
    'PickUp' => array(
        'price' => 0,
        'payment' => '',
    ),
);

if(isset($_POST['carrier'])){
    echo $_POST['carrier'];
    $price = $info_table[$_POST['carrier']]['price'];
    $payment = $info_table[$_POST['carrier']]['payment'];
    echo '<br/>' . $price . '<br/>';
    echo $payment;
}
like image 186
Kevin Avatar answered Oct 24 '22 10:10

Kevin