表单复选框,post 提交二维数组_通过POST将多维数组从表单提交到PHP


<form action="process.php" method="post">
...
check which options this product will be available in:
SIZES:
<input type="checkbox" name="options[sizes][]" value="small" />small
<input type="checkbox" name="options[sizes][]" value="medium" />medium
<input type="checkbox" name="options[sizes][]" value="medium" />large
 
COLORS:
<input type="checkbox" name="options[colors][]" value="red" />red
<input type="checkbox" name="options[colors][]" value="blue" />blue
<input type="checkbox" name="options[colors][]" value="green" />green
<input type="checkbox" name="options[colors][]" value="orange" />orange
 
TYPES
<input type="checkbox" name="options[types][]" value="floppy" />floppy
<input type="checkbox" name="options[types][]" value="compact" />compact
<input type="checkbox" name="options[types][]" value="hard" />hard
<input type="checkbox" name="options[types][]" value="digital" />digital
<input type="checkbox" name="options[types][]" value="analog" />analog
 
...
</form>

 

 

Array
(
    ...
    [options] => Array
        (
            [sizes] => Array
                (
                    [0] => small
                    [1] => large
                )
            [colors] => Array
                (
                    [0] => red
                    [1] => green
                )
            [types] => Array
                (
                    [0] => floppy
                    [1] => analog
                    [2] => digital
                )
        )
    ...
)

 

 

 

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> <style> .form-group{ height: 26px; } .control-label{ margin-top:8px; } #fat-btn{ margin-left: 12px; } </style> </head> <body> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12"> <div class="form-group"> <label class="col-sm-1 control-label">检测时间</label> <div class="col-sm-4" style="width: 109px;"> <input type="text" value="09:00" class="form-control sleepStart" ></input> </div> <div class="col-sm-4" style="width: 109px;"> <input type="text" value="17:30" class="form-control sleepStop" ></input> </div> </div> </div> </div> <div id="time"></div> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12"> <div class="form-group"> <button id="fat-btn" class="btn btn-primary" type="button">添加 </button> </div> </div> </div> </body> <script> $(function() { $("#fat-btn").click(function() { if($('.sleepStart').length > 2) { return alert('超过三个了') } else { var htm = ""; htm += "<div class='row'>"; htm += "<div class='col-md-12 col-sm-12 col-xs-12'>"; htm += "<div class='form-group'>"; htm += "<label class='col-sm-1 control-label'>检测时间</label>"; htm += "<div class='col-sm-4' style='width: 109px;'>"; htm += "<input type='text' value='09:00' class='form-control sleepStart'></input></div>"; htm += "<div class='col-sm-4' style='width: 109px;'>"; htm += "<input type= 'text' value='17:30' class='form-control sleepStop'></input>"; htm += "</div></div></div></div>"; $('#time').append(htm); } }); }); </script> </html>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM