1

I have created custom form and on submit of that form, I need to fetch data from database and need to display that content in well structured format in different template.

I am able to create form, on submission, I am able to fetch data from database but I am not able to pass that result to another template and display data on that template. I have also tried with

 function nexposed_menu() {
  $items = array();

  $items['form-example'] = array(
    'title' => 'Example Form',
    'description' => 'A form to mess around with.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('nexposed_form'),
    'access callback' => TRUE
  );
  return $items;
}

function nexposed_form($form, &$form_state) {
  $toppings = array(
    'Jan' => t('Jan'),
    'Feb' => t('Feb'),
    'Mar' => t('Mar')
  );

  $form['month'] = array(
    '#title' => t('Months'),
    '#type' => 'checkboxes',
    '#description' => t('Select the Month'),
    '#options' => $toppings,
  );
  $form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Click Here!'),
  );

  return $form;
}

function nexposed_form_validate($form, &$form_state) {
}

function nexposed_form_submit($form, &$form_state) {
  drupal_set_message(t('Search submitted successfully.'));
  $query = db_select('node', 'node');
  $query = $query->fields('node', array('nid', 'title'));
  $query->condition('node.type', 'events'); 
  $rows = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

  return theme('event_page', array('data' => $result, 'paging' => $paging));
}

Where $result contains data in the key value pair format, but that template is not called rather no result is displayed.

Any help regarding this is highly appreciated. Thanks in advance.

2 Answers 2

2

Please update your _menu function with this code.

  function filterevents_menu() {
  $items = array();

    $items['events-filter'] = array(
        'title' => 'Events Listing',
        'description' => '',
        'page callback' => drupal_get_form,
          'page arguments' => array('filterevents_form'), 
        'access callback' => TRUE,
    );
    return $items;
  }

And then clear drupal cache. Hope it will work.

Thanks.

1
  • That's working for me !!! Great job
    – Anurag
    Commented May 10, 2016 at 13:04
0

Please follow the procedure given in the below link, might be it will work

http://themery.com/dgd7/advanced-theming/forms/with-templates

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.