function oauth_common_edit_form_context_validate in OAuth 1.0 7.3
Same name and namespace in other branches
- 6.3 oauth_common.admin.inc \oauth_common_edit_form_context_validate()
- 7.4 oauth_common.admin.inc \oauth_common_edit_form_context_validate()
Validate submission of the preset edit form.
File
- ./
oauth_common.admin.inc, line 438 - Administration pages for OAuth module.
Code
function oauth_common_edit_form_context_validate(&$form, &$form_state) {
$values = $form_state['values'];
// Check that the authorization level names are unique within the context
$levels = array();
$default_exists = FALSE;
foreach ($values['authorization_levels'] as $key => $level) {
if (is_numeric($key) && !empty($level['name']) && !$level['delete']) {
if (!empty($levels[$level['name']])) {
form_error($form['authorization_levels'][$key]['name'], t('Authorization level name must be unique.'));
}
else {
if (preg_match("/[^A-Za-z0-9_\\*]/", $level['name'])) {
form_error($form['authorization_levels'][$key]['name'], t('Authorization level name must be alphanumeric or underscores only.'));
}
}
if (empty($level['title'])) {
form_error($form['authorization_levels'][$key]['title'], t('Authorization levels must have a title.'));
}
$default_exists = $default_exists || $level['default'];
$levels[$level['name']] = TRUE;
}
}
// Check that we actually got a number as access token lifetime
if (!is_numeric($values['authorization_options']['access_token_lifetime'])) {
form_error($form['authorization_options']['access_token_lifetime'], t('The access token lifetime must be numeric.'));
}
// Check that at least one default authorization level is checked when
// authorization level selection is disabled.
if (!$default_exists && $values['authorization_options']['disable_auth_level_selection']) {
form_error($form['authorization_options']['disable_auth_level_selection'], t('You must select at least one default authorirization level if level selection is disabled.'));
}
}