I wonder if anyone has found a solution to the problem I'm seeing. I've built a very simple "beginner's form" in drupal.

function simple_nameform() {
    $form = array(
        '#method'           => 'post',
        '#prefix'           => '<div class="staf">',
        '#suffix'           => '</div>',
        'your_name'         => array(
            '#title'        => t('Your Name'),
            '#type'         => 'textfield',
            '#description'  => t('Please enter your name')
        'submit'            => array(
            '#type'         => 'submit',
            '#value'        => t('submit')
    return $form;

I've put this form in a module, with info, I've enabled the block in admin. When I'm on the main page render I run the commands

<div class="simple_overlay" id="simple">
    <h1>Send to a Friend</h1>
        $output = drupal_get_form('simple_nameform');
<?php // debug purposes only

The form does not appear to render from the "drupal_render" line, however, the $output variable is most definitely full of something that looks very much like it might be a drupal form.

(it's a huge array filled with my form elements. at parts it even manages to render some of the elements to page correctly).

Anyone with an idea of what I've missed?



<?php print render(drupal_get_form('simple_nameform')); ?>

EDIT -- My original answer was incorrect in that it applies to Drupal 6.

it seems that the form builder function in D7 needs 2 arguments, $form and $form_state

function simple_nameform($form, &$form_state) {

I wonder if the _valdiate and _submit function aren't also required, as they are present in the D7 example here: http://api.drupal.org/api/drupal/includes--form.inc/group/form_api/7

if that doesn't work, try using hook_forms() to register your form with a module

original solution for D6

$output = drupal_get_form('simple_nameform');
print $output;

drupal_get_form returns a rendered form. notice the last line here: drupal_get_form()

also, unrelated, you probably need to add a line to your submit button:


        'submit'            => array(
            '#type'         => 'submit',
            '#value'        => t('submit'),
            '#executes_submit_callback' => true

and to make debugging easier, try this:

<?php // debug purposes only

(the 2nd arg of print_r makes it return inline instead of pooping at the top of your document.)

  • See I'd tried that (with echo instead of print) and got the result "Array" printed in the space that I expected the form to be rendered in. One of the non-standard drupal features installed is "chaos tools" is there perhaps something that is creating a conflict ? – Alex C Aug 5 '11 at 16:07
  • is this drupal 6.x or 7.x? – tmsimont Aug 5 '11 at 16:43
  • nevermind -- just saw in your tags.. it's 7 – tmsimont Aug 5 '11 at 16:53
  • that form generation link might turn out to be far more useful than what I was doing. the command render() as opposed to drupal_render appeared to have the desired effect. – Alex C Aug 5 '11 at 18:16
  • thanks so much for your help though. I've learned a good deal from your answer. – Alex C Aug 5 '11 at 18:16

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.