function rate_widget_form_validate in Rate 6.2
Same name and namespace in other branches
- 7 rate.admin.inc \rate_widget_form_validate()
Form validate.
File
- ./
rate.admin.inc, line 505 - Rating admin
Code
function rate_widget_form_validate($form, &$form_state) {
// Validate machine readable name
if (!preg_match('/^[a-z\\_0-9]+$/i', $form_state['values']['name'])) {
form_set_error('name', t('The machine readable name may only contain alphanumeric characters and underscores.'));
}
// Validate vote tag
if (!preg_match('/^[a-z\\_0-9]+$/i', $form_state['values']['tag'])) {
form_set_error('tag', t('The vote tag may only contain alphanumeric characters and underscores.'));
}
if ($form['#widget_customizable']) {
// Validate option values
$used_values = array();
foreach ($form_state['values'] as $name => $value) {
if (preg_match('/^value([0-9]+)$/', $name, $match)) {
if (empty($value)) {
continue;
}
if (!preg_match('/^\\-?[0-9]+$/', $value)) {
form_set_error($name, t('Values must be integers'));
continue;
}
if (in_array($value, $used_values)) {
form_set_error($name, t('You may not use the same value twice.'));
}
$used_values[] = $value;
if ($form_state['values']['value_type'] == 'percent') {
if ($value < 0 || $value > 100) {
form_set_error($name, t('Percentages must be between 0 and 100'));
}
}
}
}
if (!count($used_values)) {
form_set_error('', t('Each widget must have at least one option.'));
}
}
}