function socialfield_service_validate in Social field 7
Validates widget elements.
1 string reference to 'socialfield_service_validate'
- socialfield_field_widget_form in ./
socialfield.module - Implements hook_field_widget_form().
File
- ./
socialfield.module, line 820 - Provides a field for adding social services links.
Code
function socialfield_service_validate($element, &$form_state) {
$index = 0;
$items = array();
// If remove button was pressed error validation is not necessary.
$items['validate_link'] = TRUE;
if (isset($form_state['clicked_button']['#socialfield_delete'])) {
$items['validate_link'] = FALSE;
}
for ($i = 0; $i < $element['social_buttons']['#num_elements']; $i++) {
while (!isset($element['social_buttons']['element_' . $index])) {
// There is no element with this index. Moving on to the next possible element.
$index++;
}
$current_element = $element['social_buttons']['element_' . $index];
$index++;
// If url doesn`t contain 'http' we concatenate it to url value.
if ($current_element['url']['#value']) {
$parsed_url = parse_url($current_element['url']['#value']);
if (empty($parsed_url['scheme'])) {
$current_element['url']['#value'] = 'http://' . ltrim($current_element['url']['#value'], '/');
}
}
$items[] = array(
'service' => $current_element['#service'],
'url' => $current_element['url']['#value'],
'weight' => $current_element['weight']['#value'],
);
}
// Changing submitted form values during form validation.
form_set_value($element, $items, $form_state);
}