0

I've written the following module and it's not working. By that I mean it's not printing the #prefix to the webform above the 'resource_name' field. In fact, it's not printing it anywhere on the page. I'm trying to alter a webform-created node. I've already verified the form_id is correct as listed. And according to the webform the 'resource_name' is the field key for the field above which I want to place the #prefix markup. Any help is appreciated, thanks.

Note also that yes I've enabled the module.

    <?php

    function webformalter_form_alter(&$form, &$form_state, $form_id) {
      // Check when the right form is passed
      if ($form_id == ' webform_client_form_289') {

        // Add the directions
        $form['resource_name'] = array(
          '#prefix' => '<p>Do you know of a high-quality resource that should be in our 
listings?</p><p>Please let us know! We will review it before publishing it, and we will 
follow up with any questions.</p>',
        );
  }
}

1 Answer 1

1

I think your not setting the prefix correctly. I think you want to do something more like this:

if ($form_id == ' webform_client_form_289') {
    // Add the directions
    $form['submitted']['#prefix'] = '<p>Do you know of a high-quality resource that should be in our listings?</p><p>Please let us know! We will review it before publishing it, and we will follow up with any questions.</p>';
}

Looks like what your trying to do on in your code is set resource_name to be an array with just prefix in it.

4
  • thanks I edited it but it still won't work. 'resource_name' is just a field in the form (there are other fields), fyi. Not sure if that's the problem. When I dpm($form) the resource_name variable is buried under #node > webform > components > resource_name. But when I try adding the prefix with that elongated path it doesn't work either. So now I'm not sure what else to try. Other ideas?
    – Sage
    Apr 28, 2015 at 19:58
  • Wait, are you trying to alter the form that creates the webform, or a component on the form that webform generates for you? Apr 28, 2015 at 20:03
  • @Sage, actually, on my test site, the form element is stored at $form['submitted']['resource_name'] (I updated my answer to that). If that is in your $form variable, that's probably where you want to make your changes.
    – Jance
    Apr 28, 2015 at 20:06
  • 1
    @Jance cool, yea, thanks that worked. For others, this is the URL that explains how to hook_form_alter webforms specifically: drupal.org/node/1558246.
    – Sage
    Apr 28, 2015 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.