Forms: Allow ability to add hidden fields
On hold
This PR and task has now been passed over to Zap for next steps.
Fixes https://github.com/Automattic/jetpack/issues/21241
Proposed changes:
- This PR includes:
- The initial foundation added here: https://github.com/Automattic/jetpack/pull/40329 (allows adding hidden fields via the inspector). Modifications to that include:
- Creating a button to add new fields (allows for cases when the value field is blank)
- Adding the hidden fields to form HTML if the value is blank for any name / value hidden field pairs, as well as a new set of filter, which allows third party integration for dynamically added values.
- Warning messaging if duplicate names are spotted (but not preventing this from happening)
- An initial framework to allow using hidden fields within the Salesforce form variation for the organization ID. An earlier commit included allowing for the actual hidden field, but this is pared back for now so functionality remains as it was (to simplify this initial hidden fields PR).
Additional notes:
- See https://github.com/Automattic/vulcan/issues/601 for more information on possible next steps in terms of extending hidden fields and, how that can tie in to other functionality.
- In terms of using hidden fields on more than one form on a post / page, this is currently staying as a 'to do', until form reusability steps related to unique form IDs are in place.
Other information:
- [ ] Have you written new tests for your changes, if applicable?
- [ ] Have you checked the E2E test CI results, and verified that your changes do not break them?
- [ ] Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?
Jetpack product discussion
https://github.com/Automattic/jetpack/issues/21241 See also https://github.com/Automattic/vulcan/issues/601
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
On a self-hosted or WoA site, apply this PR via the Jetpack Beta plugin or locally. On Simple, with a sandboxed Simple site apply the changes using the command in the generated comment below.
- Create a new post and add a form block - any form variation will do, but for ease you can use the Contact Form variation.
- Once the form is added, select the form block and notice in the inspector there is a new section for hidden fields.
- You should be able to add new name / value pairs with the Add button.
- If you duplicate a name, you should see a warning message 'on blur' (when clicking elsewhere out of the name field). This should disappear once the duplicate name is changed.
- If you test using a pre-defined hidden field with the name '[post_id]', this should remove the value field, and replace that with the form ID.
Form response data and exporting data:
- After submitting a form that includes hidden fields, view the feedback response at
wp-admin/edit.php?post_type=feedbackand ensure the hidden field data is there. - Try exporting the data via CSV, and Google sheets. In both cases, the hidden fields names should be prefixed with '85_', which will place them after the more important form data such as name, email, etc, but before Consent and IP address.
Testing form filters:
- On self-hosted / WoA:
- Create two new sets of hidden fields. Name one [post_id] and name another 'Test', with a value 'Demo'.
- Using a code snippet plugin / functionality plugin, add the following code:
add_filter( 'jetpack_contact_form_modify_hidden_fields', 'custom_modify_hidden_field_both', 10, 3 );
function custom_modify_hidden_field_both( $updated_field, $hidden_field ) {
if ( isset( $updated_field['value'] ) && $updated_field['value'] === 'Demo' ) {
$updated_field['name'] = 'Custom Name';
$updated_field['value'] = 'Custom Value';
}
return $updated_field;
}
- Activate the snippet, then on the front-end of the site fill out the demo form with the added hidden fields.
- Check the form responses at
wp-admin/edit.php?post_type=feedback- you should see one entry for [post_id] with the post id, and you should see one entry with the name 'Custom Name' and value of 'Custom Value'. There should be no entry for 'Test' with the value 'Demo'. - Add the following snippet:
add_filter( 'jetpack_contact_form_modify_hidden_field_name', 'custom_modify_hidden_field_name', 10, 3 );
function custom_modify_hidden_field_name( $field_name, $field_value, $hidden_field ) {
if ( $field_value === '1771' ) { // replace 1771 with the post ID that your form is included in.
return 'No post ID';
}
return $field_name;
}
- Activate the snippet, then on the front-end of the site fill out the demo form with the added hidden fields.
- Check the form responses at
wp-admin/edit.php?post_type=feedback- you should see one entry for 'No post ID' with the post id, as well as the changed values from the previous values (or the original name / value pair values for those hidden fields if the other snippet is deactivated).
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
-
To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the
add/forms-hidden-field-optionbranch. -
To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-hidden-field-option
Interested in more tips and information?
- In your local development environment, use the
jetpack rsynccommand to sync your changes to a WoA dev blog. - Read more about our development workflow here: PCYsg-eg0-p2
- Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2
Thank you for your PR!
When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
- :white_check_mark: Include a description of your PR changes.
- :white_check_mark: Add a "[Status]" label (In Progress, Needs Review, ...).
- :white_check_mark: Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
- :white_check_mark: Add testing instructions.
- :white_check_mark: Specify whether this PR includes any changes to data or privacy.
- :white_check_mark: Add changelog entries to affected projects
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation :robot:
Follow this PR Review Process:
- Ensure all required checks appearing at the bottom of this PR are passing.
- Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
- You can use GitHub's Reviewers functionality to request a review.
- When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.
If you have questions about anything, reach out in #jetpack-developers for guidance!
Jetpack plugin:
The Jetpack plugin has different release cadences depending on the platform:
- WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
- WoA releases happen weekly.
- Releases to self-hosted sites happen monthly:
- Scheduled release: July 1, 2025
- Code freeze: June 30, 2025
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.
This PR is currently waiting on next steps from the Zap team.
This PR has been marked as stale. This happened because:
- It has been inactive for the past 3 months.
- It hasn’t been labeled `[Pri] BLOCKER`, `[Pri] High`, etc.
If this PR is still useful, please do a [trunk merge or rebase](https://github.com/Automattic/jetpack/blob/trunk/docs/git-workflow.md#keeping-your-branch-up-to-date) and otherwise make sure it's up to date and has clear testing instructions. You may also want to ping possible reviewers in case they've forgotten about it. Please close this PR if you think it's not valid anymore — if you do, please add a brief explanation.
If the PR is not updated (or at least commented on) in another month, it will be automatically closed.
This PR has been marked as stale. This happened because:
- It has been inactive for the past 3 months.
- It hasn't been labeled `[Pri] BLOCKER`, `[Pri] High`, `[Status] Keep Open`, etc.
If this PR is still useful, please do a [trunk merge or rebase](https://github.com/Automattic/jetpack/blob/trunk/docs/git-workflow.md#keeping-your-branch-up-to-date) and otherwise make sure it's up to date and has clear testing instructions. You may also want to ping possible reviewers in case they've forgotten about it. Please close this PR if you think it's not valid anymore — if you do, please add a brief explanation.
If the PR is not updated (or at least commented on) in another month, it will be automatically closed.
We have a follow-up to this work in another PR:
- https://github.com/Automattic/jetpack/pull/44079
Just been waiting some backend refactoring before continuing with it. I'll close this meanwhile. Thanks for the work here!