i have a dynamic form so i have no idea which kind of input there will be every time and i need to handle that, so i've done something like this
<div id="repond-questionnaire" class="modal fade in" style="display: block;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Questionnaire de Test</h4>
</div>
<div class="modal-body" id="questionnaire_here">
<form method="post" id="questionnaire_form">
<div class="form-group">
<label for="text"><h3>Who are you?</h3></label>
<textarea type="text" name="80" class="form-control" rows="3" placeholder="Text..." required="" value=""></textarea>
</div>
<div class="form-group">
<label for="focusedInput"><h3>How old are you?</h3></label>
<input type="number" name="81" class="form-control" placeholder="Number..." required="" value="">
</div>
<div class="form-group">
<label for="focusedInput"><h3>What is your email?</h3></label>
<input type="email" name="82" class="form-control" placeholder="Email..." required="" value="">
</div>
<div class="form-group">
<label for="focusedInput"><h3>Do you like our website?</h3></label>
<div class="radio">
<label class="input-lg"><input type="radio" name="83" value="Oui">Oui</label>
</div>
<div class="radio">
<label class="input-lg"><input type="radio" name="83" value="Non">Non</label>
</div>
</div>
<input type="submit" name="sumbit" id="sumbit" value="Sumbit" class="btn btn-success"></form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#repond-questionnaire').on('click', '#sumbit', function() {
// here i need to check if all inputs are empty or not
//check if they have a valid input or not for security
//because after i will send everything and upload them to the data base
$.ajax({
url: "user/sumbit_answers.php",
method: "POST",
data: $('#questionnaire_form').serialize(),
beforeSend: function() {
$('#sumbit').val("Sumbiting...");
},
success: function(data) {
$('#questionnaire_form')[0].reset();
if (data == 'exit_failure') {
alert("something wrong happened");
} else {
$('#questionnaire_here').empty();
$('#questionnaire_here').html(data);
}
}
});
});
$('#repond-questionnaire').on('click', '#close', function(event) {
$('#questionnaire_here').empty();
});
});
</script>
and i'm obliged to do this because somehow the events of the form are blocked ( even though i'm not using event.preventdefault()
, my form input are all like this
<input type='$type' name='$row[cid]' class='form-control' placeholder='$type...' required value=''>