Input Validator

Last modified: December 21, 2008 - 15:17

I've only tested this with 4.6. 4.7 and above has a much more sophisticated forms API than 4.6, so you probably wouldn't need this in 4.7 and above (though the code may help with other projects). It may be that you don't need to do client side validation in 4.6, I'm still just learning to navigate the drupal framework. :)

When you display the form you need to have the onsubmit function call Blank_TextField_Validator

form($form, $method = 'POST', $action = "apply/application_update", array('onsubmit'=> 'return blank_TextField_Validator()'));

The page must also contain the script:

<script type="text/javascript">

function blank_TextField_Validator() {
inputs = document.getElementsByTagName("input");
for (var i = 0; input = inputs[i]; ++i) {
  // className is for IE, class for FF
  if (input.value == "" && ((input.getAttribute("className") == "form-text required") || (input.getAttribute("class") == "form-text required"))){
    alert("Please fill in all required fields.");
    input.focus();
    return(false);
    }
  }
return (true);
}
</script>

 
 

Drupal is a registered trademark of Dries Buytaert.