I have a message box at the bottom of my site. I don't know how these messages manage to slip through my validations.
These are the spam messages, that somehow able to submit to my database.
JS validation:
$('#send-contact').click(function(e) {
e.preventDefault()
//Gather inputs objects
var $inputs = {}
$inputs.name = $('#contact-form #name')
.val()
.trim()
$inputs.email = $('#contact-form #email')
.val()
.trim()
$inputs.message = $('#contact-form #message')
.val()
.trim()
console.log($inputs)
// console.log($inputs.email.indexOf('*'));
if ($inputs.name.length === 0 || $inputs.email.length === 0 || $inputs.message.length === 0) {
alert('1 or more input(s) is empty! ‼️ \n\nYour message: \n\n --empty--')
return false
}
if ($inputs.message.indexOf('http') > -1) {
alert('Link is not allow in message! \n\nYour message: \n\n' + $inputs.message)
return false
}
if ($inputs.email.indexOf('@') == -1) {
alert('Check your email format! \n\nYour message: \n\n' + $inputs.email)
return false
}
if ($inputs.email.indexOf('.') == -1) {
alert('Check your email format! \n\nYour message: \n\n' + $inputs.email)
return false
}
$('#send-contact').empty()
$('#send-contact').append('<img src="/assets/fe/img/svg/default.svg" alt="Loading" style="width: 20px; float: right; padding-top: 5px; ">')
var data = {}
$.ajax({
method: 'POST',
url: '/y',
crossDomain: true,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Cache-Control': 'no-cache'
},
data: $inputs,
success: function(response) {
console.log(response)
var audio = `<audio id="audio2" controls="controls" hidden="hidden">
<source src="/assets/music/alert.mp3" type="audio/ogg">
<source src="/assets/music/alert.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>`
$('#thankModal').append(audio)
$('#send-contact').remove('img')
$('#audio2')
.get(0)
.play()
$('.loading').addClass('hidden')
$('#thankModal').modal('show')
$('#thankModal #text1').removeClass('hidden')
$('#thankModal #text1')
.text('Thank-you for your note. !')
.slideDown('slow')
setTimeout(function() {
$('#thankModal #text1').fadeOut()
$('#thankModal #text2').removeClass('hidden')
$('#thankModal #text2')
.text('Message sent. !')
.slideDown('slow')
setTimeout(function() {
$('#thankModal #text2').fadeOut()
$('#thankModal #text3').removeClass('hidden')
$('#thankModal #text3')
.text('Site will redirect. !')
.slideDown('slow')
$('#thankModal').modal('hide')
$('#reset').click()
$('label.error').hide()
$('label.valid').hide()
$('#send-contact').empty()
$('#send-contact').text('SEND')
window.open('/thank-you', '_blank')
}, 1000)
}, 1000)
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(JSON.stringify(jqXHR))
console.log('AJAX error: ' + textStatus + ' : ' + errorThrown)
alert(textStatus)
// window.open("/thank-you", "_blank");
location.reload()
}
})
})
What happened to this check?
if ($inputs.message.indexOf('http') > -1) {
alert('Link is not allow in message! \n\nYour message: \n\n' + $inputs.message)
return false
}
I tested my message box by pasting the same exact text
We always struggled to pack before a trip. What to bring, how many or how much of it, etc... So we have created this Foldable Travel Bag. It's Just So Versatile! . Easy to Fold and Unfold . Large Storage Space . Portable + Waterproof 60% OFF for the next 24 Hours ONLY + FREE Worldwide Shipping for a LIMITED time! Buy now: https://ifashiononline.shop Many Thanks, Shanel
It got stopped by the validation, which is what I expected.
How can these messages still slip through and be able to submit my form? Is this a bot that can bypass JS validation?

