V4 - How to check if javascript is disabled and redirect

delacoux 24 Nov, 2011
Hi,

just to share... I validate a lot of my forms data with JavaScript and wanted to make sure it is enabled to prevent malicious entries.

In the form I have a hidden input field : <input id="check" type="hidden" value="" name="check" />
Before show html in the load event I have the following JS code :
window.addEvent('load', function() {
var check = $('check').value
check = "ok";
$('check').value = check;
});

Then in th on Submit event I have the following custom code :
<?php
$check = $form->data['check'];
if ($check != "ok") {  
$url = 'index.php?option=com_content&view=article&id=33';
$mainframe =& JFactory::getApplication();
$mainframe->redirect($url);
}
?>


This way I redirect the user to a page saying he cannot use my forms without JavaScript enabled. My opinion is if someone does not have in 2011 JavaScript enabled on his browser, that person probably has bad intentions.

Cheers!
GreyHead 24 Nov, 2011
Hi delacoux ,

Nice validation - thank you for posting it here.

Bob
This topic is locked and no more replies can be posted.