0
我需要一個函數能夠從drupal窗體中的date_popup中檢索選定的日期這是我的窗體和我試過的代碼,我正在爲懷孕計算器做一個窗體, Drupal的我需要知道如何實現我的form.As測試日期計算我寫了一個函數值來選擇閱讀,但它給我1970-01-01日期drupal窗體來計算日期
<?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) {
//我應該寫在這裏以獲得所選日期的值並在其上添加特定時間。對於使用的測試im:
$selected_time= $_POST[''Pregnancy_Period'];
$output=$selected_time;
drupal_set_message($output);//but it's showing 1970-01-01
}
我怎樣才能把日期的每一部分單獨? – sally
我已經在上面的回答中更新了 – Clive
如果我需要在javascript中進行計算,我該怎麼做 – sally