Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am new in Drupal. I have created a form which saves the values to custom table how ever I want to display those items in a tabular format. Does any one know how to create a custom page where I can display those items.

This is what I tried: in module file

<?php $menu_items['user/campaigns/new_campaign'] = array(
        'title' => 'Campaigns',
        'type'=> MENU_CALLBACK, 
        'page callback' => 'create_campaign_form2',
        'access arguments' => array('access content'),
        'file' => 'campaigns.create_campaign2.inc',
        'weight' => 1,
    ); ?>

in campaigns.create_campaign2.inc file:

<?php function create_campaign_form2()
{
    echo 'Some HTML here';

}
?>

But it displays only displays the text, the entire css is removed please let me know what should I do. Sorry if the question is too basic.

share|improve this question
1  
you should add an return; statement to the callback function. – develkar Dec 15 '12 at 10:03

1 Answer

Use Drupal's Form API. Basically your code will look like this:

<?php 
    $menu_items['user/campaigns/new_campaign'] = array(
      'title' => 'Campaigns',
      'type'=> MENU_CALLBACK, 
      'page callback' => 'drupal_get_form',
      'page arguments' => array('create_campaign_form2');
      'access arguments' => array('access content'),
      'file' => 'campaigns.create_campaign2.inc',
      'weight' => 1,
    );
?>

<?php
   $form = array();
   $form['selected'] = array(
     '#type' => 'select',
     '#title' => t('Selected'),
     '#options' => array(
        0 => t('No'),
        1 => t('Yes'),
     ),
     '#default_value' => 'Maybe',
     '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
   );
   return $form;
?>

Notice the use of drupal_get_form() in the menu hook. This function takes the return value of create_campaign_form2, which it expects to be a PHP array, as an argument and uses that data to build the markup of the form.

This particular example will generate a form with only a select drop down. But check out the complete Form API reference for all (and there are A LOT) of the options and settings you have available to build your form. It might be intimidating at first, but the idea is quite simple: you create a PHP array that represents your form and then drupal_get_form() turns that array into a secure and well structured form. ALWAYS use the Form API to build forms in Drupal.

share|improve this answer
+1. Probably OP wants to display items saved from a form that is already built ? – Ayesh K Feb 22 at 20:05
looking at the question date, I'm wondering how on the earth I came here. – Ayesh K Feb 22 at 20:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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