Is it possible to submit a checkbox form without submit button in php?

后端 未结 2 505
感动是毒
感动是毒 2021-01-25 01:50

I am a php newbie and i am trying to create a price range system for my ecommerce website project.

so I did a checkbox form:

相关标签:
2条回答
  • 2021-01-25 02:45

    Add javascript function submit() in onchange

    <form method="POST" action="?">
    <p><input type="checkbox" name="dori" value="dori" onchange="this.form.submit()"><em> 0 - 5000</em></p>
    <p><input type="checkbox" name="bora" value="bora" onchange="this.form.submit()"><em> 5000 - 1000</em></p>       
    </form>
    
    0 讨论(0)
  • 2021-01-25 02:47

    I implemented the submission of multiple checkbox value by using php as follows. It works perfectly for me and hope that it will work for everyone .

    <?php
    session_start();
    
    
    $samsung=NULL;
    if(!empty($_POST['samsung']))
    $samsung = $_POST['samsung'];
    $_SESSION["samsung"] = $samsung;
    $samsung1 = $_SESSION["samsung"];
    echo $samsung1."<br />";
    
    $apple=NULL;
    if(!empty($_POST['apple']))
    $apple = $_POST['apple'];
    $_SESSION["apple"] = $apple;
    $apple1 = $_SESSION["apple"];
    echo $apple1."<br />";
    
    $low=NULL;
    if(!empty($_POST['low']))
    $low = $_POST['low'];
    $_SESSION["low"] = $low;
    $low1 = $_SESSION["low"];
    echo $low1."<br />";
    
    ?>
    
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Checkbox</title>
    </head>
    <body>
    <form  action="checkbox.php" method="post">
    Samsung<input type="checkbox" name="samsung"  value="samsung" onchange="this.form.submit()" <?php if(!empty($_SESSION["samsung"])){echo "checked";} ?>>
    Apple<input type="checkbox" name="apple"  value="apple" onchange="this.form.submit()" <?php if(!empty($_SESSION["apple"])){echo "checked";} ?>>
    5000-1000<input type="checkbox" name="low"  value="low" onchange="this.form.submit()" <?php if(!empty($_SESSION["low"])){echo "checked";} ?>>
    </form>
    
    </body>
    </html>
    

    Here I use session variable so that once I checked Samsung it will persist even if I checked apple . Hope this example will help you.

    0 讨论(0)
提交回复
热议问题