Hi there,

I am using Drupal7 for developing forms, but however I wasn't able to make them display on the page. I used the function drupal_get_form('my_search_form');, All it displays is a word "Array". Is there any changes in displaying the form from Drupal6 to Drupal7?


$form = drupal_get_form('my_search_form');
return $form;

function my_search_form(){

  $form['myName'] = array(
    '#type' => 'textfield',
    '#title' => 'My Name',
    '#size' => 64,
    '#maxlength' => 64,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );
  return $form;
}


function my_search_form_submit($form, &$form_state) {
  $s = $form_state['values']['firstName'];
  drupal_redirect_form($form, 'final_page');
}

Comments

nevets’s picture

You should really use a module for that (it appears to be the body of a node).

Anonymous’s picture

nevets is right this code should really be in a module, but you can solve your problem by passing the output from drupal_get_form into the render() function.

$form = render(drupal_get_form('my_search_form'));
return $form;
OptimusPrime23’s picture

thanks for the help :)

aaustin’s picture

Thanks this helped me with this scenario. In a custom module, I was returning a form as part of more information on the page in the usual variable $output. The form would render if it was the only output but as soon as I tried to add more output: I just got the before-mention "ARRAY":

// This worked
<?php
  function myfunction(){
    $output = drupal_get_form('my_form');
    return $output;
  }

//This didn't work:
  function myfunction(){
    $output = drupal_get_form('my_form');
    $output .= 'Some more output';
    return $output;
  }

//But this did:
  function myfunction(){
    $output = render(drupal_get_form('my_form'));
    $output .= 'Some more output';
    return $output;
  }
?>

I can see why this is the case but it is just another slight change to remember from drupal 6 to 7. I'm so glad there are so many answers on the d.o site as I work on my first d7 module.

nevets’s picture

And this should work

  function myfunction(){
    $output = array();
    $output['my_form'] = drupal_get_form('my_form');
    $output['my_message'] = array('#type' => 'markup', '#value' => 'Some more output);
    return $output;
  }