Hi all,

I'm themeing a form that contains two select elements and a submit button, and I want to position the Submit at the top of the form so that I can float the two selects right so that the form will appear as (right aligned):

rather than



So I try doing this in my form's theme function:

function theme_my_form($form){
  $output  .= '<div class="float-right" >' . drupal_render($form) . '</div>';
  $output  .= '<div class="float-right" >' . drupal_render($form['first_select']) . '</div>';
  $output  .= '<div class="float-right" >' . drupal_render($form['first_select']) . '</div>';
  return $output;
}

But that doesn't really work, as the first line just spits out the whole form.

So two questions, what is the voodoo behind the call to drupal_render($form)? And can I replace it with something that just spits out the Submit button or form element etc?

Cheers,
Toby

Comments

half_brick’s picture

Solved my own problem. I just put:

function theme_my_form($form){
  $output  .= '<div class="float-right" >' . drupal_render($form['submit']) . '</div>';
  $output  .= '<div class="float-right" >' . drupal_render($form['first_select']) . '</div>';
  $output  .= '<div class="float-right" >' . drupal_render($form['first_select']) . '</div>';
  $output  .= '<div class="float-right" >' . drupal_render($form) . '</div>';
  return $output;
}

I'd still like to more about why the

 $output  .= '<div class="float-right" >' . drupal_render($form) . '</div>';

line is necessary though...

hellig_usvart’s picture

in case you didn't get an answer to your question yet, this is an excerpt from the forms api quickstart documentation:

The rendering code keeps track of which elements have been rendered, and will only allow them to be rendered once. Notice that drupal_render is called for the entire form array at the very end of the theming function, but it will only render the remaining unrendered element, which in this case is the submit button. Calling drupal_render($form) is a common way to end a theming function, as it will then render any submit buttons and/or hidden fields that have been declared in the form in a single call.