function quant_admin_settings_validate in Quant 6
Same name and namespace in other branches
- 7 quant.admin.inc \quant_admin_settings_validate()
File
- includes/
forms.inc, line 239 - Form-building functions
Code
function quant_admin_settings_validate(&$form, &$form_state) {
// Check width
if (!is_numeric($form_state['values']['quant_width']) || strlen($form_state['values']['quant_width']) > 4 || strlen($form_state['values']['quant_width']) < 2) {
form_set_error('quant_width', t('The width must be a number that is between 2 and 4 digits'));
}
// Check height
if (!is_numeric($form_state['values']['quant_height']) || strlen($form_state['values']['quant_height']) > 4 || strlen($form_state['values']['quant_height']) < 2) {
form_set_error('quant_height', t('The height must be a number that is between 2 and 4 digits'));
}
// Iterate through colors
$colors = array();
// Store all colors in a single array
for ($i = 0; $i < QUANT_PALETTE_AMOUNT; $i++) {
$color = $form_state['values']['quant_palette_color_' . $i];
// If color exists, make sure it's valid
if ($color) {
$colors[] = strtoupper($color);
// Remove form value to avoid multiple color variables
unset($form_state['values']['quant_palette_color_' . $i]);
}
}
// Make sure we at least have one color
if (empty($colors)) {
form_set_error('color', t('You need to enter at least one color.'));
}
else {
// Save colors in a single variable
variable_set('quant_palette', $colors);
}
}