0

I need to change the date form of quiz module in quiz.module on line 1307 it was this:

  $form['quiz_availability']['quiz_open'] = array(
    '#type' => 'date',
    '#title' => t('Open Date'),
    '#default_value' => _quiz_form_prepare_date($node->quiz_open),
    '#description' => t('The date this @quiz will become available.', array('@quiz' => QUIZ_NAME)),
    '#after_build' => array('_quiz_limit_year_options'),
  );
  $form['quiz_availability']['quiz_close'] = array(
    '#type' => 'date',
    '#title' => t('Close Date'),
    '#default_value' => _quiz_form_prepare_date($node->quiz_close, variable_get('quiz_default_close', 30)),
    '#description' => t('The date this @quiz will cease to be available.', array('@quiz' => QUIZ_NAME)),
    '#after_build' => array('_quiz_limit_year_options'),
  );

and I changed it to this:

 $form['quiz_availability']['quiz_open'] = array(
    '#type' => 'date_select',
    '#date_format' => 'Y-m-d H:i',
    '#title' => t('Open Date'),
    '#default_value' => _quiz_form_prepare_date($node->quiz_open),
    '#description' => t('The date this @quiz will become available.', array('@quiz' => QUIZ_NAME)),
    '#after_build' => array('_quiz_limit_year_options'),
  );
  $form['quiz_availability']['quiz_close'] = array(
    '#type' => 'date_select',
    '#date_format' => 'Y-m-d H:i',
    '#title' => t('Close Date'),
    '#default_value' => _quiz_form_prepare_date($node->quiz_close, variable_get('quiz_default_close', 30)),
    '#description' => t('The date this @quiz will cease to be available.', array('@quiz' => QUIZ_NAME)),
    '#after_build' => array('_quiz_limit_year_options'),
  );

but now the webpage gives an error. How do I fix this error? The Error:

Please supply a valid date. PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'quiz_open' at row 1: INSERT INTO {quiz_node_properties} (vid, nid, aid, number_of_random_questions, randomization, backwards_navigation, repeat_until_correct, quiz_open, quiz_close, takes, show_attempt_stats, keep_results, time_limit, pass_rate, summary_pass, summary_pass_format, summary_default, summary_default_format, quiz_always, feedback_time, display_feedback, tid, has_userpoints, allow_skipping, allow_resume, allow_jumping, show_passed, mark_doubtful) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17, :db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20, :db_insert_placeholder_21, :db_insert_placeholder_22, :db_insert_placeholder_23, :db_insert_placeholder_24, :db_insert_placeholder_25, :db_insert_placeholder_26, :db_insert_placeholder_27); Array ( [:db_insert_placeholder_0] => 24 [:db_insert_placeholder_1] => 22 [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 2 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 2013-08-03 01:02 [:db_insert_placeholder_8] => 2013-09-02 15:13 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 1 [:db_insert_placeholder_11] => 2 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => 75 [:db_insert_placeholder_14] => [:db_insert_placeholder_15] => plain_text [:db_insert_placeholder_16] => [:db_insert_placeholder_17] => plain_text [:db_insert_placeholder_18] => 1 [:db_insert_placeholder_19] => 1 [:db_insert_placeholder_20] => 1 [:db_insert_placeholder_21] => 0 [:db_insert_placeholder_22] => 0 [:db_insert_placeholder_23] => 1 [:db_insert_placeholder_24] => 1 [:db_insert_placeholder_25] => 1 [:db_insert_placeholder_26] => 1 [:db_insert_placeholder_27] => 0 ) in quiz_insert() (in line 739 /home/...../public_html/...../sites/all/modules/quiz-7.x-4.0-beta1/quiz/quiz.module).

3
  • If I add "#date_format" to '#type' => 'date', my problem is solved.But I cant add this to this type Aug 3, 2013 at 13:55
  • You should really avoid changing module files directly. Next time you upgrade you will have to manually apply your changes again, it will be a hell to maintain :) Aug 3, 2013 at 14:27
  • OK,But what should I do? Aug 3, 2013 at 14:33

1 Answer 1

0

When you want to override forms created by core or custom modules you should implement hook_form_alter() in a custom module.

It will look something like

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id)  {
  if ($form_id == 'quiz_form') {
    $form['quiz_availability']['quiz_open']['#type'] = 'date_select';
  }
}

Or as a hook_form_FORM_ID_alter() and then it would look like this

function mymodule_form_quiz_form_alter(&$form, &$form_state, $form_id) {
  $form['quiz_availability']['quiz_open']['#type'] = 'date_select';
}
1
  • I think it doesn't need this.Please check this file's and say how should I change them!quiz-datetime.inc line 19,quiz.module on line 3834,quiz.module on line 1467,quiz.module on line 1307.I want to change the date type to the date_select or add hour and minute selection to the date type.The main file to save the time in the database is quiz-datetime.inc and I should change it.can you help me? Aug 4, 2013 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.