function signaturefield_field in SignatureField 6
Implementation of hook_field().
File
- modules/
content.inc, line 117 - Content module integration.
Code
function signaturefield_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
// Do validation on the field values here. The widget
// will do its own validation and you cannot make any
// assumptions about what kind of widget has been used,
// so don't validate widget values, only field values.
case 'validate':
if (is_array($items)) {
foreach ($items as $delta => $item) {
// The error_element is needed so that CCK can
// set an error on the right sub-element when
// fields are deeply nested in the form.
$error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
if (is_array($item) && isset($item['_error_element'])) {
unset($item['_error_element']);
}
if (!empty($item['value'])) {
if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) {
form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array(
'%name' => $field['widget']['label'],
'%max' => $field['max_length'],
)));
}
}
}
}
return $items;
// This is where you make sure that user-provided
// data is sanitized before being displayed.
case 'sanitize':
foreach ($items as $delta => $item) {
$example = check_plain($item['value']);
$items[$delta]['safe'] = $example;
}
}
}