43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
$( document ).ready(function() {
|
|
$('#comments').on('submit', function(e) {
|
|
e.preventDefault();
|
|
var $this = $(this);
|
|
var uri = baseUri+'modules/cms_comments/ajax_comments.php';
|
|
|
|
var pseudo = $('#name').val();
|
|
var mail = $('#email').val();
|
|
var comments = $('#comments_content').val();
|
|
|
|
if(pseudo === '' || mail === '' || comments === '') {
|
|
alert('Les champs doivent êtres remplis');
|
|
} else {
|
|
var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
|
|
if(!reg.test(mail)) {
|
|
alert('Email non valide');
|
|
} else {
|
|
$.ajax({
|
|
url: uri,
|
|
type: $this.attr('method'),
|
|
data: $this.serialize(),
|
|
dataType: 'json',
|
|
success: function(jsonData) {
|
|
$('.msg-comment').remove();
|
|
if(!jsonData.errors) {
|
|
$('#name').val('');
|
|
$('#email').val('');
|
|
$('#comments_content').val('');
|
|
$('#comments').prepend('<p class="msg-comment alert alert-success">Commentaire ajouté avec succès, en attente de modération</p>');
|
|
} else {
|
|
if(jsonData.html) {
|
|
$('#comments').prepend('<p class="msg-comment alert alert-danger">'+jsonData.html+'</p>');
|
|
} else {
|
|
$('#comments').prepend('<p class="msg-comment alert alert-danger">Impossible d\'ajouter le commentaire</p>');
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|