I've followed different tutorials but I cannot seem to override a field on my webform via a function in template.php.

Theme is called: 'myTheme'
Id of the form is: 'webform_client_form_76'
Id of the input: 'edit-submitted-henkilotiedot-etunimi'
Name of the input: 'submitted[henkilotiedot][etunimi]'

The function I think should work:

function myTheme_webform_form_76 (&$vars) {
    $vars['form']['submitted']['edit-submitted-henkilotiedot-etunimi']['#value'] = t('Name');

What is the correct format to override webform elements?

1 Answer 1

function [themename]_form_webform_client_form_76_alter(&$form, &$form_state, $form_id) {
// code of altering
  • Thanks, but I seem to also have the format of the code to alter wrong as well: $form['form']['submitted']['edit-submitted-henkilotiedot-etunimi']['#value'] = t('Name');
    – tommyf
    Mar 27, 2013 at 9:16
  • Setup devel module and then use kpr($form); to research $form structure. Looks like it should be $form['submitted']['henkilotiedot_etunimi']['#value'] = t('Name'); Mar 27, 2013 at 9:23
  • Thanks for the advice. It turns out I needed $form['submitted']['henkilotiedot']['etunimi']['#default_value'] = t('Name');
    – tommyf
    Mar 27, 2013 at 9:41

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.