1

I have webform component labels like this:

Did [your pet] have any illnesses?

and I want to replace [your pet] with a variable token?

Do I need to write a custom module or can I do this by editing one of the theme .tpl files?

Tried this code as suggested:

<?php

/*
 * Implementation of hook_form_alter()
 */

drupal_set_message(t('Outwith the hook'), 'warning'); // display outwith the hook

function wit_bootstrap_form_alter(&$form, &$form_state, $form_id) {

drupal_set_message(t('Inside the hook'), 'warning'); // display within the hook


 // target my form / my field
  if ($form_id == "webform_client_form_1") {
    // target my form / my field

    if ($form['neutered']['#title']) {
        $title = $form['neutered']['#title'];
        $token_val = 'freelo';//get_tokenised_value(); // Which ever way you handle that...
        $title = str_replace('[your pet]', $token_val, $title);
        $form['neutered']['#title'] = $title;
    }
  }
}
0

hook_form_alter() should allow you to so.

Within your theme you should be able to do something like :

/*
 * Implementation of hook_form_alter()
 */
function my_theme_form_alter(&$form, &$form_state, $form_id){
  // target my form / my field
  if ($form_id == "my_form") {
    if ( $form['my_field']['#title'] ) {
      $title =  $form['my_field']['#title'];
      $token_val = get_tokenised_value(); // Which ever way you handle that...
      $title = str_replace('[your pet]', $token_val, $title);
      $form['my_field']['#title'] = $title;
    }
  }
}

Also check the forms api reference to see what things you can set / alter on forms.

  • Thanks for your help with this. We have done as you suggest but to no avail. Here is what we have, the form component is still unaltered. We can display a warning message outwith the hook but not within. Any help/advice you can offer would be very much appreciated: – Arthur Wilson Oct 21 '15 at 12:18
  • Will send you the code, can't get it to format. new to this – Arthur Wilson Oct 21 '15 at 12:34
  • Sure. Edit your question to add the code you've tried. – rtome Oct 21 '15 at 13:13
  • Ok, I've added a copy of our code, based on you r suggestions, to or original question – Arthur Wilson Oct 22 '15 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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