Community Documentation

Input Validator

Last updated December 21, 2008. Created by stokito on September 19, 2006.
Edited by piersonr. Log in to edit this page.

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>

About this page

Drupal version
Drupal 4.6.x
Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here