JavaScriptを使って、フォームのエラーチェック機能を搭載しましょう。
以下がコードサンプルになります。エラーが全てなくなると送信されるように、htmlのformタグには、from.phpを指定してあります。
▼JavaScript
$(function() {
$(".alert").hide();
var sendF= true;
$("#submitBtn").click(function(){
if(!$("#text").val()){
$("#tSec .alert").show();
sendF = false;
}else{
$("#tSec .alert").hide();
}
var radioC = $('input[name="radio"]:checked').length;
if(radioC == 0){
$("#rSec .alert").show();
sendF = false;
}else{
$("#rSec .alert").hide();
}
var checkC = $('input[name="checkbox"]:checked').length;
if(checkC < 1){
$("#cSec .alert").show();
sendF = false;
}else{
$("#cSec .alert").hide();
}
if($("select").val() == "none"){
$("#sSec .alert").show();
sendF = false;
}else{
$("#sSec .alert").hide();
}
if(!$("#textarea").val()){
$("#taSec .alert").show();
sendF = false;
}else{
$("#taSec .alert").hide();
}
if(sendF == false){
return false;
}
});
});
▼CSS
▼HTML
