开发者

Drupal 6 - How to customise form layout using theme

开发者 https://www.devze.com 2023-01-04 22:11 出处:网络
I have create a new content type and added new form items using CCK.I need to customise the layout of the form which I\'ve partially managed using css and moving items around and adding custom markup

I have create a new content type and added new form items using CCK. I need to customise the layout of the form which I've partially managed using css and moving items around and adding custom markup in the form_alter hook. However, this still开发者_JAVA技巧 isn't enough as the weightings don't appear to be doing exactly what I want them to do.

Is there a way I can do this using a theme.tpl.php file?

Thanks Steve


once in a time I was in the same situation and found a quite easy solution.

I needed a highly customized registration form and form_alter was a mess. So I used a template for the form and printed each field into the html output.

First register a new template for the form in template.php of you theme.

<?php
function your-theme-name_theme() {
  return array( 
    'user_register' => array(
      'arguments' => array('form' => NULL),
      'template' => 'user-register',
    ),
  );
}
?>

Now add a new template to your theme. In my case "user_register.tpl.php". Add the following lines to it, so that the form still works.

<?php
print drupal_render($form['form_build_id']);
print drupal_render($form['form_id']);
print drupal_render($form['form_token']);
?>

From there on you can add as much html as you want and put the form fields where ever you need them. Here are examples for the gender and birthday field. As you can see you have to use the internal CCK names.

<?php print drupal_render($form['field_profile_gender']); ?>
<?php print drupal_render($form['field_profile_birthday']); ?>

I have not tested this for any other form than user_register, but I guess it should work as long as the template name equals the name of the form.

I hope this will help you.

Regards

Mike

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号