By gte451f on
I have been reading up on trying to override the rendering of certain elements in my form but am making a mistake somewhere.
I have a generic node type created and inside the hook_form element have placed the following code...
$form['#theme'] = '_theme_game_form';
Shouldn't this tell Drupal to send the form through this function before outputting to the screen?
Well it isn't so I must be making a mistake.
How can I tell drupal that I want to intercept the form and theme specific elements before outputting to a page?
Comments
Bump!
Anyone have any idea?
Thanks!
Still Stuck...
I just don't get it guys.
I have looked in to
hook_form_alter but it looks like that is for adding additional field elements.
I have looked into the examples provided by upload.module and related links but in both cases, it is an outside module acting on a node based module.
I am creating a node based module and I want to override the default rendering logic of some particular form elements I outlined back in
hook_form.
Should I set the theme of the form in hook_form_alter?
Some supplement reading for anyone following along....
http://drupal.org/node/40947
http://drupal.org/node/37775
This may or may not help
Not much time, so a reference to a small Howto: Theme Drupal forms with PHPTemplate. The example is about story_node_form.
You should also be able to theme the form with a function theme_form_id($form) in your module eg theme_yournodetype_node_form (haven't tested).
--
When your problem is solved, please post a follow-up to the thread you started.
Thanks for tip. This does
Thanks for tip. This does help alittle but I must confess I have already started looking in this direction. Overall, it seems cleaner from a design perspective to confine theming to .tpl files but in this example, the level of granularity was the fieldset. Put another way, I can only move a field set around, how do I start controlling how field elements (check box, textfield) get placed within the fieldset?
It's difficult to render
It's difficult to render children before a visible containing parent.
In the example, suppose you also wanted to swap the 'Authored by' and 'Authored on field' and wrap the Authored by field in a div one way to do this is:
--
When your problem is solved, please post a follow-up to the thread you started.
Yes this is less then idea
Yes this is less then ideal but we're getting somewhere. I stumbled on another approach that also has some drawbacks.
This method allows one to render individual form elements but if they are within a fieldset you could run into problems. In this case, I have extracted the field elements one by one to display horizontally in a table. Still what do do with that pesky field set? I suppose it still has to show up but it will appear as empty now.
Perhaps I can just recreate my module to forego fieldsets and "roll my own" but why should we have to settle!
I seem to remember there being an attribute that dictates if a form element has been displayed. Perhaps we could just disable the fieldset.
Another approach would be to use the prefix/suffix attributes to create some sort of table like effect.
I could go with inline divs as another alternative.
*Forgive my poor CSS skills!
Still even the CSS approach means that I would either commit other users to my CSS or put the burden on them to create styles they liked.
Render children, not the fieldset
To render the children of a fieldset but not the fieldset itself use the following code. Example is from story form; here we're trying to render all the fields contained in the fieldset, but not the fieldset itself.
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.