0

I have altered a webform by adding a date field in different language like chinese in Drupal 7. But what steps are required to store custom field value in database and retrieving value when webform results are accessed?

I used hook_form_alter() to add custom date field in the existing webform, but its value doesn't get stored in database. Do I need to add some extra code to store value of custom field in db?

I am sharing my code.

function tekege_grievanceform_form_alter(&$form, &$form_state, $form_id) { //print_r($form_id);exit;
switch ($form_id) {
    /* for chinese */
    case 'webform_client_form_60224':
        $form['submitted']['dob'] = array(
            '#type' => 'fieldset',
            '#title' => t('出生日期'),
            '#weight' => 4,
            '#prefix' => '<div class="chinese_dob" id="webform_chinese_dob">',
            '#suffix' => '</div>',
            '#required' => 'true'
        );

        $form['submitted']['dob']['dob_month'] = array(
            '#type' => 'select',
            '#default_value' => array('month' => '月'),
            '#options' => array('month' => t('月'),
                1 => t('1 月'), 2 => t('2 月'), 3 => t('3 月'), 4 => t('4 月'), 5 => t('5 月'), 6 => t('6 月'), 7 => t('7 月'), 8 => t('8 月'), 9 => t('9 月'), 10 => t('10 月'), 11 => t('11 月'), 12 => t('12 月'),
            ),
            '#description' => t('Select month.'),
            '#required' => true,
        );

        /* for 31 days */
        $form['submitted']['dob']['dob_day_31'] = array(
            '#type' => 'select',
            '#default_value' => array('day' => '日'),
            '#options' => array('day' => t('日'), 1 => t('1'), 2 => t('2'), 3 => t('3'), 4 => t('4'), 5 => t('5'), 6 => t('6'), 7 => t('7'), 8 => t('8'), 9 => t('9'), 10 => t('10'), 11 => t('11'), 12 => t('12'),
                13 => t('13'), 14 => t('14'), 15 => t('15'), 16 => t('16'), 17 => t('17'), 18 => t('18'), 19 => t('19'), 20 => t('20'), 21 => t('21'), 22 => t('22'), 23 => t('23'), 24 => t('24'),
                25 => t('25'), 26 => t('26'), 27 => t('27'), 28 => t('28'), 29 => t('29'), 30 => t('30'), 31 => t('31')),
            '#description' => t("Thirty-One Days."),
            '#required' => true,
        );

        $form['submitted']['dob']['dob_year'] = array(
            '#type' => 'select',
            '#default_value' => array('year' => '年'),
            '#options' => array('year' => t('年'), 1 => t('2013'), 2 => t('2012'), 3 => t('2011'), 4 => t('2010'), 5 => t('2009'), 6 => t('2008'), 7 => t('2007'), 8 => t('2006'),
                9 => t('2005'), 10 => t('2004'), 11 => t('2003'), 12 => t('2002'), 13 => t('2001'), 14 => t('2000'), 15 => t('1999'), 16 => t('1998'), 17 => t('1997'),
                18 => t('1996'), 19 => t('1995'), 20 => t('1994'), 21 => t('1993'), 22 => t('1992'), 23 => t('1991'), 24 => t('1990'), 25 => t('1989'), 26 => t('1988'),
                27 => t('1987'), 28 => t('1986'), 29 => t('1985'), 30 => t('1984'), 31 => t('1983'), 32 => t('1982'), 33 => t('1981'), 34 => t('1980'), 35 => t('1979'), 36 => t('1978'), 37 => t('1977'), 38 => t('1975'),
                39 => t('1974'), 40 => t('1973'), 41 => t('1972'), 42 => t('1971'), 43 => t('1970'), 44 => t('1969'), 45 => t('1968'), 46 => t('1967'), 47 => t('1966'),
                48 => t('1965'), 49 => t('1964'), 50 => t('1963'), 51 => t('1962'), 52 => t('1961'), 53 => t('1960'), 54 => t('1959'), 55 => t('1958'), 56 => t('1957'),
                57 => t('1956'), 58 => t('1955'), 59 => t('1954'), 60 => t('1953'), 61 => t('1952'), 60 => t('1951'), 61 => t('1950'),
            ),
            '#description' => t('Select year.'),
            '#required' => true,
        );
    }
 }
7
  • How did you altered webform ? using form alter ? You can add a field date to webform which can store and retrieve results like any other fields...
    – Anil Sagar
    Commented Jan 23, 2014 at 7:08
  • @AnilSagar I have added custom field in webform by form alter for some different requirements.Kindly let me know how its value can be stored and retrieved? Commented Jan 23, 2014 at 7:11
  • Please explain your requirements in your question.. Otherwise it's difficult to answer your question.. Please update your question with all details...
    – Anil Sagar
    Commented Jan 23, 2014 at 7:13
  • @AnilSagar I have updated my question.Please have a look. Commented Jan 23, 2014 at 7:27
  • Additionally you can add webform.api functions (like _webform_submit_component or hook_webform_submission_presave or hook_webform_submission_insert...)
    – xurshid29
    Commented Jan 23, 2014 at 7:29

1 Answer 1

0

Solved: I was using devlopment version of webform module that was restricting my custom date fields of webform to get stored in database. It was required to be updated. Anyways thanks for replying.

Your Answer

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

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