tags:

views:

18

answers:

1

Hi,

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 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

A: 

Hi Steven,

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

mikewink
Mike, This looks superb! I will definitely give this a shot... I ended up using more markup in the prefix/suffix just to get what I wanted but its a mess... thanks for this!
Steven Cheng