I'm trying to theme the page where users create new accounts. Essentially I would like to re-do the layout of that page. (If there is a better way, please let me know)

In the user module menu hook for creating a new user, I got rid of the drupal_get_form and call a function of mine which in turn calls a theme_user_create_new_account function. Reason being that I wanted to override the theme function in the template.php file.

So that is what I have done so far. In my template.php I have:

function phptemplate_user_create_new_account($fields = array()) {
...
  return _phptemplate_callback('user_create_account', array('fields' => $output);
}

The "$fields" parameter contains an array of form elements

Array
(
    [user_registration_help] => Array
        (
            [#value] => 
        )

    [account] => Array
        (
            [#type] => fieldset
            [#title] => Account information
            [name] => Array
                (
                    [#type] => textfield
                    [#title] => Username
                    [#default_value] => 
                    [#maxlength] => 60
                    [#description] => Your preferred username; punctuation is not allowed except for periods, hyphens, and underscores.
                    [#required] => 1
                )

            [mail] => Array
                (
                    [#type] => textfield
                    [#title] => E-mail address
                    [#default_value] => 
                    [#maxlength] => 64
                    [#description] => A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.
                    [#required] => 1
                )

        )

I'm hoping to render the html of name and mail elements and pass them to my callback function 'user_create_account'.

However I'm having some difficulty. As I go through the array (above) I pass the 'name' array to theme_textfield(); and the html is rendered but I also get a warning message:

warning: implode() [function.implode]: Bad arguments. in /.../includes/form.inc on line 622.

So I'm stuck with 2 questions.
1. Am I making this too complicated because there is an easier way of doing this?
2. Why am I getting the warning message when I pass the 'name' and 'mail' arrays to theme_textfield()?

Comments

gpk’s picture

Hmm if you want a form to be processed by Drupal's Forms API then you need drupal_get_form(). It does much more than themeing.

But what it *does* do is make sure that a suitable theme function for the form is called, if one exists. I assume you are working with the path user/register for which the form builder funciton is http://api.drupal.org/api/function/user_register/5. If you define a theme_user_register() function in your template.php (or phptemplate_user_register() for that matter, which would also work; arguably it's best to use the engine's namespace where possible for your own theme functions) then it will automatically be used to theme the form. No theme_user_register() is actually defined in Drupal core. You can also create page-user-register.tpl.php if you want to use a different page template for this page.

If you need to make any changes to the form definition, use http://api.drupal.org/api/function/hook_form_alter/5.

Note that if you do it this way then admin/user/user/create will also use your custom theme function, but not your custom page template (since the internal path is different).

Also check out http://api.drupal.org/api/file/developer/topics/forms_api.html/5 if you've not done so already.

gpk
----
www.alexoria.co.uk

number3’s picture

Great that make my task that much more easier, because now when I pass the 'mail' and/or 'name' arrays into the theme_
() method I don't get that warning anymore.

Thanks for the help. Should be fun theming this "bad boy" the way this client wants.

Peace.