Created on 17 July 2024, 2 months ago
Updated 25 July 2024, 2 months ago

Is it possible to include additional fields in the reply form?

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States solarDog

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @solarDog
  • 🇮🇳India arunkumark Coimbatore

    @solarDog

    Yes, you can use the hook_form_alter() and add your additional form field. Replace the default submit handler with your custom submit. Write the logic to handle your new fields into it.

    Example:

    /**
     * Implements hook_form_alter().
     */
    function MODULE_NAME_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
      if ($form_id == 'webform_email_reply_form') {
        $form['new_field'] = [
          '#type' => 'textfield',
          '#title' => 'First name',
          '#required' => TRUE,
        ];
    
        // Custom submit handler.
        $form['#submit'][] = 'MODULE_NAME_webform_email_reply_form_submit';
      }
    }
    
    /**
     * Custom submit handler for webform_email_reply_form.
     */
    function MODULE_NAME_webform_email_reply_form_submit($form, FormStateInterface $form_state) {
      $new_field = $form_state->getValue('new_field');
      // Do the Other logic.
    }
    
Production build 0.71.5 2024