1

I have the following code.

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

  $items['mymodules/page'] = array(
    'title' => t('my module settings'),
    'description' => t('change values here'),
    'page callback' => 'mymodule_page',
    //'page arguments' => array('mymodule_page'),
    'access arguments' => array('access administration pages'),
    'type' => MENU_CALLBACK,
   );

  return $items;
}

function mymodule_page() {
  return drupal_get_form('test_form');
}

function test_form() {
  $form = array();
  $brandarray = array('nokia','siemes');

  $form['mymodule_brand'] = array(
    '#type' => 'select',
    '#title' => t('Brand'),
    '#default_value' => variable_get('mymodule_brand', 'nokia'),
    '#options' => $brandarray,
    '#description' => t('Change this.'),
  );

  $form['my_markup'] = array(
  '#markup' => '<p>Lorem ipsum</p>',
  );

  return system_settings_form($form);
}

This works perfectly. What I wanted to so is returning a form and page content together, i.e after the page content, in a menu callback function; I tried using the following code:

function mymodule_page() {
  $variable =  drupal_get_form('test_form');
  $variable .= '<div class="newclass">here</div>';

  return $variable;
}

But it prints something like the following:

    Array
    here

How do I return both the form and content together in a menu callback?

  • In Drupal 7, the arguments for your test_form() are test_form($form, &$form_state); you should then remove the $form = array() line from that form builder. See Form generation. – kiamlaluno Sep 20 '11 at 23:25
5

In Drupal 7 drupal_get_form() returns a render array instead of a string, so you should return a render array as well:

return array(
  'my_content' => array(
    '#type' => 'markup',
    '#markup' => 'Some markup',
  ),
  'my_form' => drupal_get_form(...),
);
  • you mean to say i cannot return both form and other contents together ?? because the content after the form will be more then a markup ie. it will have a image and other content also. So is there any other way to do it? – Hacker Sep 21 '11 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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