function number_process in Content Construction Kit (CCK) 6
Same name and namespace in other branches
- 6.3 modules/number/number.module \number_process()
- 6.2 modules/number/number.module \number_process()
Process an individual element.
Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.
The $fields array is in $form['#field_info'][$element['#field_name']].
1 string reference to 'number_process'
- number_elements in modules/
number/ number.module - Implementation of FAPI hook_elements().
File
- modules/
number/ number.module, line 407 - Defines numeric field types.
Code
function number_process($element, $edit, $form_state, $form) {
$field_name = $element['#field_name'];
$field = $form['#field_info'][$field_name];
$field_key = $element['#columns'][0];
$value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '';
$value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value;
$element[$field_key] = array(
'#type' => 'textfield',
'#title' => $element['#title'],
'#description' => $element['#description'],
'#required' => $element['#required'],
'#default_value' => $value,
// Need to allow a slightly larger size that the field length to allow
// for some configurations where all characters won't fit in input field.
'#size' => isset($field['precision']) ? $field['precision'] + 2 : 12,
'#maxlength' => isset($field['precision']) ? $field['precision'] : 10,
'#attributes' => array(
'class' => 'number',
),
);
$prefixes = array();
$suffixes = array();
if (!empty($field['prefix'])) {
$prefixes = explode('|', $field['prefix']);
$element[$field_key]['#field_prefix'] = array_pop($prefixes);
}
if (!empty($field['suffix'])) {
$suffixes = explode('|', $field['suffix']);
$element[$field_key]['#field_suffix'] = array_pop($suffixes);
}
switch ($field['type']) {
case 'number_float':
$element['#element_validate'] = array(
'number_float_validate',
);
break;
case 'number_integer':
$element['#element_validate'] = array(
'number_integer_validate',
);
break;
case 'number_decimal':
$element['#element_validate'] = array(
'number_decimal_validate',
);
$element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.';
$element['#precision'] = isset($field['precision']) ? $field['precision'] : 10;
$element['#scale'] = isset($field['scale']) ? $field['scale'] : 2;
break;
}
return $element;
}