i'm using semantic-ui form validation in my code. I'm sending a data to server for checking if is has the same value-or not. if server value has same with my sending data, writing a message, i want to show that message into form validation prompt are. But how! Please give me a hand about this. Here is my code:
<form class="ui form segment">
<div class="field">
<label>Email</label>
<input type="email" name="email" id="email">
</div>
<div class="ui submit button">Validate Email</div>
<div class="ui error message"></div>
</form>
<script>
$('.ui.form')
.form({
on: 'blur',
fields: {
email: {
identifier : 'email',
rules: [{type: 'email', prompt: 'This is not a valid email adress.'}]
}
},
onSuccess: function() {
return false; // false is required for dont let submit the form, (prevent refreshing)
}
})
.api({
url : 'register.php',
method : 'POST',
serializeForm: true,
onResponse: function(response) {
if(response == 0){
console.log('You are eligible, you can join us');
}else{
console.log('Your email already in our database, try another one');
}
}
});
</script>
Here is my register php;
if(isset($_POST['email'])){
$q="SELECT * FROM users WHERE email = '$_POST[email]'";
$r = mysqli_query($dbc, $q);
$response = mysqli_num_rows($r);
echo $response;
}
As you can see, i'm consoling results from server. I want to prompt this message to form validation prompt, like 'This is not a valid email adress.'.
Thanks already.