0
        <?php


        //https://www.drupal.org/node/1806758   
        function mhzipcode_block_info() {

          $block = array();
          $block['mhzipcode'] = array(
            'info' => t('mhzipcode'),
          );
          return $block;
        }
        /* 
        Implement hook_block_view
        */

        function mhzipcode_block_view($delta= ''){
          $block = array();
          switch($delta) {
           case 'mhzipcode' :   
             $block['content'] = drupal_get_form('mhzipcode_storage_form');         
           break;
          }
          return $block;
        }
        /*
        Implement zipcode_view function 
        */

        function mhzipcode_storage_form($form, &$form_state) {
          if ($form_state['rebuild']) {
            $form_state['input'] = array();
          }
          // Initialize
          if (empty($form_state['storage'])) {
            if (empty($form_state['input'])) {
              $_SESSION['constructions'] = 0;
            }
            // Put the initial thing into the storage
            $form_state['storage'] = array(
              'thing' => array(
            'zipcode' => '',
            'phonenumber' => '',
              ),
            );
          }
          // Count how often the form is constructed.
          $_SESSION['constructions']++;
          //drupal_set_message("Your form has been saved.");

          $form['zipcode'] = array(
            '#type' => 'textfield',
            '#title' => 'Zip Code',
            '#size' => 15,
            '#default_value' => $form_state['storage']['thing']['zipcode'],
            '#required' => TRUE,
          );
          $form['phonenumber'] = array(
            '#type' => 'textfield',
            '#size' => 15, 
            '#title' => 'Phone Number',
            '#default_value' => $form_state['storage']['thing']['phonenumber'],

          );
           $form['continue_submit'] = array(
            '#type' => 'submit',
            '#value' => 'Continue submit',
            '#submit' => array('mhzipcode_storage_form_submit'),
          );


          if (isset($_REQUEST['cache'])) {
            // Manually activate caching, so we can test that the storage keeps working
            // when it's enabled.
            $form_state['cache'] = TRUE;
          }

          return $form;
        }
        function mhzipcode_storage_form_submit($form, &$form_state) {
          $zipcodeAlias = $form_state['values']['zipcode'];
          $zip_code = db_query("select PhoneNumber from {Phone_number} where Zipcode='".$zipcodeAlias."'")->fetchField();   
          die;
          $form_state['storage']['thing']['phonenumber'] = $zip_code; 
          $form_state['rebuild'] = TRUE;
        }

Form doesn't submitted and mhzipcode_storage_form_submit isn't working .doesn't load this function code , and die is not load .

1
  • Please take the time to ask a clear and concise question - a code dump with an incomprehensible string of non-grammar after it is not high enough quality for this site. Describe clearly what happens, what you expect to happen, error messages that you receive, etc. Also, make sure you trim your code down to the least possible amount to reproduce the problem. This is an essential step to take before asking development questions here. 90% of the time doing this will help you find the problem yourself.
    – Clive
    Jul 28, 2014 at 12:21

2 Answers 2

1

I have tested it in my module, i didn't get any issue. It worked fine for me. The output i received after using print_r(); and die(); in my submit function is

Array
(
    [zipcode] => 23423423
    [phonenumber] => 423423423
    [continue_submit] => Continue submit
    [form_build_id] => form-zVFjX4fMorTyOI6m3JE0SL3w0_rSCTsVzEho63Qb1u4
    [form_token] => Pg3erepuKQvtsCSQT-3G7FWLivsSWDH69P0Z3YfRD6M
    [form_id] => mhzipcode_storage_form
    [op] => Continue submit
)  

Just try it in a separate module where no extra code exists and then debug the issue. It can be conflict with some module or any other issue. Hope it will help.

1
  • Plz how to check the conflict with some module ? any idea
    – user34531
    Jul 28, 2014 at 6:45
1

I have checked your code and its perfectly working for me. The form is getting validated if the 'zipcode' field is left empty and it also getting submitted. Please check whether you have written any jQuery 'preventDefault()' function. You can easily identify this by disabling the Javascript of your brower. Once after disabling your browser and check the form submission.

Please clear the browser and Drupal cache too... :) Good Luck

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