I have a webform with id 32.

I created a template (which works fine) in my theme/templates folder named webform-form-32.tpl.php.

I also created a preprocess function in my template.php file. My theme is called emuse and my hook is:

function emuse_preprocess_webform_form_32(&$vars){
}
but this doesnt get called.

Comments

quicksketch’s picture

Priority: Major » Minor

This is a minor problem in the scheme of Webform since you could just use hook_preprocess_webform_form() in the mean time and check the NID. I'm not sure how (or if) this problem is solvable because Webform is already doing what's necessary to support pattern-based templates. This may be a core bug.

In hook_theme():

    'webform_form' => array(
      'render element' => 'form',
      'template' => 'templates/webform-form',
      'pattern' => 'webform_form_[0-9]+',
    ),

And in webform_client_form():

  // Add a theme function for this form.
  $form['#theme'] = array('webform_form_' . $node->nid, 'webform_form');

Those two pieces should be all that's needed to make pattern-based callbacks work. The fact that it works for templates but not preprocess functions makes me think this is a core problem.

simon.fryer’s picture

Version: 7.x-4.x-dev » 7.x-4.0-rc5
Issue summary: View changes

Hey,

Did this ever get resolved?

I get the feeling that HOOK_preprocess_webform_form isn't working?

This is my code in template.php. I've also tried in a module with the same result.

<?php
function anzac_preprocess_webform_form(&$vars) {
  $vars['form']['#attributes']['class'][] = 'xyz';
  $vars['form']['#attributes']['enctype'] = 'simon';

  $vars['form']['submitted']['#attributes']['class'][] = 'simon'; 

  var_dump($vars['form']['#attributes']);
}
?>

The dump is as i'd expect, the 2 standard web-form classes, and my additional 'xyz' class in a 3 key array. I've even tried to break the enctype to see if that works, with no luck. The form output remains with the 2 default classes, and enctype is as default.

Am i doing something wrong, i just need to inject a class into
and i thought preprocess should achieve this but preprocess seems to be firing, but either too late, at the wrong point, or being overwritten?

Sorry to bump and old issue but it's the same issue as far as i can tell?

DanChadwick’s picture

@simon.fryer - You have having a different issue. The original issues is that THEMENAME_preprocess_webform_form_NNN (where NNN is the node id) isn't being called by the theme system. You are suggesting that THEMENAME_preprocess_webform_form is being called, but that the changes you make the to the form are not being used to build the form.

Since your var_dump happens, your theme function is being called. I suggest that you step out of your preprocess function and look at the other preprocess functions that are being called. I wonder if one of them is overwriting the form.

Also, make really, really sure that you have declared (&$vars) and not ($vars), because that would match your symptoms.

Your bug lies outside of webform.

DanChadwick’s picture

Status: Active » Closed (won't fix)

@simon-fryer -- I looked into this. You are too late at this point that HOOK_preprocess_webform_form is called to affect the form element. It is processing the contents of the form. If you want to affect the form attributes, use hook_form_alter.

I also confirmed the original issue. There is nothing that webform can do to fix this, so I'm closing the issue.