1 form.inc form_process_html_datetime($element)

Combine html_date and html_time form elements.

Related topics

File

core/includes/form.inc, line 3258
Functions for form and batch generation and processing.

Code

function form_process_html_datetime($element) {
  $value = $element['#value'];
  // Conversion to a timestamp has happened, possibly in a preview.
  // Get it back into an array for the form.
  if (is_numeric($value) && (int) $value == $value) {
    $value = array(
      'date' => format_date($value, 'custom', DATE_FORMAT_DATE),
      'time' => format_date($value, 'custom', DATE_FORMAT_TIME),
    );
  }
  // Catch possible problems.
  if (!is_array($value) || !isset($value['date']) || !isset($value['time'])) {
    $value = array(
      'date' => '',
      'time' => '',
    );
  }
  $element['#tree'] = TRUE;
  $element['date'] = array(
    '#type' => 'html_date',
    '#default_value' => $value['date'],
  );
  $attributes = $element['#attributes'];
  if (isset($attributes['date'])) {
    $element['date']['#attributes'] = $attributes['date'];
  }

  $element['time'] = array(
    '#type' => 'html_time',
    '#default_value' => $value['time'],
  );
  if (isset($attributes['time'])) {
    $element['time']['#attributes'] = $attributes['time'];
  }

  return $element;
}