簡介
埋在form裡面的<input type=”submit” />以及<button>,只要按下就會觸發form執行
reportvalidity()
手動觸發「檢核」提示
form#myForm
input(type="text" required)
input(type="submit")
button(onclick="myForm.reportValidity()") click me
checkValidity()
檢查表單檢核有沒有過,有通過的話回傳true,沒通過的話回傳false
form#myForm
input(type="text" required)
input(type="submit")
//Console Panel
myForm.checkValidity()
reset()
清空表單的input內容
form#myForm
input(type="text" required)
input(type="submit")
//Console Panel
myForm.reset() //清空內容
PHP陣列取值
name如果命名成xxx[]的話,傳到PHP會直接變成陣列
適合用在很多checkbox時
<form action="ttt.php" method="post"> <input type="checkbox" name="user[]" value="草莓" id="strawberry" /> <label for="strawberry">草莓</label> <input type="checkbox" name="user[]" value="橘子" id="orange" /> <label for="orange">橘子</label> <input type="checkbox" name="user[]" value="香蕉" id="banana" /> <label for="banana">香蕉</label> <br> <br> <input type="submit" name="your_submit" /> </form> <?php if(!empty($_POST['your_submit'])){ for ($i=0; $i < count($_POST['user']); $i++) { echo $_POST['user'][$i].'<br>'; } } ?>