Submission of programatically added fields

Created on 7 November 2023, over 1 year ago
Updated 2 December 2023, over 1 year ago

Problem/Motivation

I have an ever-increasing subset of hidden fields that should be added to every form in my site.
I created helper update-hook functions to add new fields to the form, but now forms have too many fields and editing becomes cumbersome, so I tried adding the fields through a webform_submission_form_alter hook.

The fields are added an can be seen on the rendered HTML with:
$form['elements'][$field_name] = [
'#type' => 'hidden',
];
but the value of this field is never available on the webform_submission data.
I have also tried copying the exact same array keys as a standard hidden field, but it didn't help.

My goal is to have this field value sent through a remote_post handler, possibly with a token of form [webform_submission:values:field].

Is there a way to do this with the current webform version? Any suggestions on what is possible?

πŸ’¬ Support request
Status

Closed: outdated

Version

6.2

Component

Code

Created by

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

Comments & Activities

  • Issue created by @luiscarvalho
  • Status changed to Closed: outdated over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    Hidden fields must be added as elements to the webform for these fields to work as expected.

    A few thoughts...

    • Write a custom module that programmatically updates all hidden fields across all webforms when a global hidden field is added or removed. For example, you could add a custom attribute to the hidden fields to track all global hidden fields.
    • Create a custom composite element containing all the hidden fields and a single place to manage them.
Production build 0.71.5 2024