Skip to content

Instantly share code, notes, and snippets.

@LarsEliasNielsen
Created March 19, 2014 13:27
Show Gist options
  • Save LarsEliasNielsen/9641592 to your computer and use it in GitHub Desktop.
Save LarsEliasNielsen/9641592 to your computer and use it in GitHub Desktop.
Drupal 7 Module Development: Validate
<?php
/**
* Implements hook_validate().
*
* Validation for configuration form. Since we need a number in the
* limit-textfield, we check that the input is correct.
*
* @url: https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_validate/7
*/
function espn_news_form_validate($form, &$form_state) {
// Get current value from input.
$espn_news_limit = $form_state['values']['espn_news_limit'];
// Check that input is a number.
if (!is_numeric($espn_news_limit)) {
form_set_error('espn_news_limit', t('Limit must be a number.'));
}
// Here you can check for negative numbers.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment