Created
March 19, 2014 13:27
-
-
Save LarsEliasNielsen/9641592 to your computer and use it in GitHub Desktop.
Drupal 7 Module Development: Validate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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