function flag_form_validate in Flag 5
Same name and namespace in other branches
- 6.2 includes/flag.admin.inc \flag_form_validate()
- 6 includes/flag.admin.inc \flag_form_validate()
- 7.3 includes/flag.admin.inc \flag_form_validate()
- 7.2 includes/flag.admin.inc \flag_form_validate()
Validate required checkboxes on our form.
FAPI has a problem validating #required checkboxes: if previously non-empty checkboxes are cleared, FAPI won't detect this.
File
- includes/
flag.admin.inc, line 377 - Contains administrative pages for creating, editing, and deleting flags.
Code
function flag_form_validate($form_id, $form_values, $form) {
// Fix checkboxes.
foreach (element_children($form) as $field) {
if ($form[$field]['#type'] == 'checkboxes' && $form[$field]['#required'] && !array_filter($form_values[$field])) {
form_error($form[$field], t('!name field is required.', array(
'!name' => $form[$field]['#title'],
)));
}
}
if ($form_values['link_type'] == 'confirm') {
if (empty($form_values['flag_confirmation'])) {
form_set_error('flag_confirmation', t('A flag confirmation message is required when using the confirmation link type.'));
}
if (empty($form_values['unflag_confirmation'])) {
form_set_error('unflag_confirmation', t('An unflag confirmation message is required when using the confirmation link type.'));
}
}
$flag = $form_values['_flag'];
unset($form_values['_flag']);
$flag
->form_input($form_values);
$flag
->validate();
}