我需要一个函数,以便能够从 drupal 表单中的 date_popup 中检索选定的日期,这是我的表单和我尝试过的代码,我正在为怀孕计算器制作一个表单,并且我是 drupal 中的新手,我需要知道如何实现我的表格中的日期计算。在测试时,我编写了一个函数来读取选定的值,但它给了我 1970-01-01 日期
<?php
/*
*Implementing hook_menu
*/
function Pregnancy_menu() {
$items['form/Pregnancy'] = array(
'title' => 'Pregnancy Calculator',
'page callback' => 'drupal_get_form',
'page arguments' => array('Pregnancy_form'),
'access callback' => TRUE,
);
return $items;
}
function Pregnancy_form($form_type) {
$form['Pregnancy_Period'] = array(
'#type' => 'date_popup',
'#title' => 'Date of your last menstrual period',
'#date_format' => 'Y-m-d',
'#date_text_parts' => array('year'),
'#date_increment' => 30,
'#date_year_range' => '-1:0',
'#default_value' => date(Y) . date(M) . date(D),
);
$form['Calculate_Forward'] = array(
'#type' => 'submit',
'#value' => t('Calculate Forward'),
);
$form['Reset_form'] = array(
'#type' => 'submit',
'#value' => t('Reset this Form'),
);
$form['Conception_result'] = array(
'#type' => 'textfield',
'#title' => t('Conception Occurred:(about two weeks after last menstrual period)'),
'#prefix' => '<div style="float:left;">',
'#suffix' => '</div>',
);
$form['First_trimester_Ends'] = array(
'#type' => 'textfield',
'#title' => t('First Trimester Ends :(12 weeks)'),
'#prefix' => '<div style="float:left;">',
'#suffix' => '</div>',
);
$form['Second_trimester_Ends'] = array(
'#type' => 'textfield',
'#title' => t('Second Trimester Ends :(27 weeks)'),
'#prefix' => '<div style="float:left;">',
'#suffix' => '</div>',
);
$form['Due_Date'] = array(
'#type' => 'date_popup',
'#title' => 'Estimated Due Date (40 weeks)',
'#date_format' => 'Y-m-d',
'#date_text_parts' => array('year'),
'#description' => t('Plus or Minus 2 weeks'),
'#date_increment' => 30,
'#date_year_range' => '+1:+1',
'#default_value' => date(Y) . date(M) . date(D),
);
$form['Calculate_Backward'] = array(
'#type' => 'submit',
'#value' => t('Calculate Backward'),
);
return $form;
}
function Pregnancy_form_submit($form, &$form_state) {
//我应该在这里写什么来获取所选日期的值并添加一个特定的时间。为了测试我使用:
$selected_time= $_POST[''Pregnancy_Period'];
$output=$selected_time;
drupal_set_message($output);//but it's showing 1970-01-01
}