0

Trying to theme a form into all the pieces available, passed my $form and $vars through hook_preprocess_HOOK but in my tpl i would like the exact render() representation of the fields and variables and the form itself like:

print $form_tag.
      $form_input1.
      $form_input2.
      $theme_var1.
      $form_closure; <!-- build_id,token_id -->
 ?>

Where there are declared in the preprosess_HOOK as

$form = $variables['form'];
$variables['form_tag'] = render($form); 
$variables['form_input1'] = render($form['input1']);
$variables['closure'] = drupal_render_children($form);
...

Is it possible to have all this variables of produced HTML in my tpl? like form start tag and closure and render correctly all the inner fields? Thank you

2
  • is this a form you have created or a form in core or drupal modules? Commented Jan 27, 2013 at 4:01
  • this is a form in a custom module
    – Pan Chrono
    Commented Jan 27, 2013 at 10:42

2 Answers 2

0

I am not sure if this is what you are trying to do. But from the question I feel that you just want to re arrange the form in an order of your choice.

The best place to do that is with in a hook_form_alter function. Rather than the preprocess_HOOK.

Every form element has a property called #weight This could be used to arrange the forms in order the one with higher weight would go down.

3
  • Thanks mohammad but the form is arranged. I need to produce a template that has every element of the form available for themer for example and a theme_hook on his template of the theme to have the variables available also like: $form_tag = <form id="" ...> $fieldset = <fieldset> .. </fieldset> $closure = <input type="hidden" build_id etc .. is this possible?
    – Pan Chrono
    Commented Jan 27, 2013 at 10:26
  • what would be the use case? Commented Jan 27, 2013 at 10:28
  • 100% front end handling of things in the template
    – Pan Chrono
    Commented Jan 27, 2013 at 11:24
0

Well the answer is simple , i returned the content using a theme function e.g.

return theme('mytheme',$form)

Entering

$form['#theme']

in the form array and

'render element' => form 

in my hook_theme solved the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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