0

Using Drupal 7 and Webform (both up to date), I'm looking for a way to add a button that when clicked, set the value of a field.

I can add a button using code like this:

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

switch ($form_id) { 

case 'webform_client_form_ID':
  $form['alt_button'] = array(
  '#type' => 'submit',
  '#value' => t('Alternative Action'),
);

I now need to figure how to perform the action of changing the value of one of the the webform field when this button is clicked...

Any help will be appreciate!

1

You will have to create a button in a

function hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
    // Your code here.
}

and use the #ajax property of the button to update the field when the button is clicked.

The examples D7 module has some nice AJAX examples that will show you how the mechanism works.

1
  • Thank you very much! It seems full of sense, but way too complicated for me...
    – Fumble
    Jan 12 '17 at 14:12

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .