Hi,
I'm new to webform and trying to theme a form. I've checked the instructions that come with the module. The given method (of creating webform_form_nodeid.tpl.php) only allows you to change the content area between description, title, submitted by fields. How to get at these? I could use node-webform.tpl.php but I don't know how to render the existing form fields within that. Also the instructions tell you how to move a field to another fieldset but don't say anything about actual themeing - how to render form fields within an example layout? Any examples or tips would be really appreciated.

Comments

davemybes’s picture

This might help you: http://drupal.org/node/79086. If you need more help, let me know.

quicksketch’s picture

Priority: Critical » Normal

Hi there chu, thanks for trying out webform. I'm not clear on what you want to accomplish. In what way are you trying to present your form? i.e. Are you trying to put it in columns or add spacing? If so, most of this kind of theming should be done with CSS. All the form elements have unique IDs and classes to help you move things around as you wish.

The instructions included with webform are not actually for the styling of the page that contains the webform, but rather gives you a way to alter the content of the form itself. Most users shouldn't need to alter the structure of the form since webform provides most of the options needed to setup the form properly.

Okay, I'm going to stop typing because incrn8 just posted a link to much better instructions.

@incrn8: That's awesome! I had no idea someone had written handbook page for theming webforms. So cool. Unfortunately, the last round of changes to webform were pretty drastic, so it's a little out of date. We're now using component identifiers instead of names to identify the fields. I'll post a comment on the handbook page.

davemybes’s picture

Yeah, true, I haven't had the time to document the new changes (which make webform MUCH better, by the way) in my previous tutorial post. However, it should give chu a start. I will update that tutorial of mine soon. Any other major changes in the works that might affect my tutorial?

adub’s picture

Am I right in understanding that all styling for webforms must be done with CSS only? So for example, if we don't want to show 'submitted by' we have to use display: hidden. This approach doesn't really work if you are theming an existing design template as you would normally drop the node fields into place of some 'lorem ipsum' sample text.

Anyway, I gave that a try but failed at the first field I tried to style. The webform node description field doesn't have any class or id and as far as I understand CSS has no ancestor or antecedent selectors so there's no way to style it. I could use the node-webform.tpl.php approach here as this is my only webform but I can't find any reference on how I would render the form.

quicksketch’s picture

If you're not wanting to style the form itself (which is what the handbook page and the THEMING.txt file explain), then you'll take the node-webform.tpl.php approach that you suggested. The form is rendered is rendered as part of the $content variable in the template file, which is why we need the other theming function for styling the form seperately.

So to describe removing the 'submitted by' line, just make a duplicate of your node.tpl.php file named $node-webform.tpl.php, and delete the <?php print $submitted?> line and anything else you want to change about the layout around the form.

quicksketch’s picture

hmm, that $ symbol slipped in there. Name your file 'node-webform.tpl.php'.

adub’s picture

I'm getting somewhere with this using a two-pronged approach as above - thanks for the advice so far.

Is there a way to change a) label text for fields and b) label and attributes for the submit button?

davemybes’s picture

To change a label title, just change it in your webform setup. Alternatively, you can put something like the following code in your webform_form_formID.tpl.php file (you can ignore the opening and closing php codes - they're just there to get the pretty colors and formatting):

$form['submitted']['fieldname'] = array(
    '#title' => 'Enter your new title here',
);

For the submit button, I think you pretty much have to go with the code option above. The submit button is accessed using the following code (these are the default settings):

$form['submitbutton'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
    '#weight' => '1000',
);

Note that the submit button is not part of the submitted fieldset. Change '#value' to get a different name for it. You can add #prefix and #suffix attributes if you want to add more html code to it too.

adub’s picture

Very helpful thanks. I noticed what looks like a small bug when changing the submit button: the class changes from 'form-submit' to 'form-' and cannot be overwritten. Not sure if that's a known issue.

quicksketch’s picture

Status: Active » Closed (fixed)

Glad we could help. I haven't noticed the submit class issue. If it looks like this is webform specific, please open a new issue just for that. Thanks.