
By OptimusPrime23 on
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
You should really use a
You should really use a module for that (it appears to be the body of a node).
nevets is right this code
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.
thanks for the help :)
thanks for the help :)
Thanks
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":
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.
And this should work
And this should work