How to Dynamically Set Email Subject Lines in PDF Forms Using Field Values
Question details
The user wants to configure a PDF form submission button to automatically insert specific form field data, such as a username or ID, into the email subject line when the form is submitted.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms that users will fill out and submit directly via email.
- Observed behavior
- The goal is to replace the generic built-in submit action with a custom script that dynamically populates the email subject based on user input in the form fields.
Ensure that your PDF editing software supports JavaScript for interactive forms. You will also need to verify the exact field name in your PDF form that contains the data you wish to display in the email subject.
Use Custom JavaScript for the Submit Action
Bypass the default submit action and assign a custom JavaScript code snippet to your submission button to dynamically pull field values.
The built-in submit feature in most PDF editors sends the document with a static subject line. By using the 'this.mailDoc' API method, you can retrieve a specific field's value and assign it directly to the 'cSubject' parameter of the outgoing email.
Open your PDF form in editing mode and click on the submit button you want to configure to select it.
Right-click the selected button, choose 'Properties' from the context menu, and navigate to the 'Actions' tab.
Choose 'Run a JavaScript' from the 'Select Action' dropdown menu and click the 'Add' button.
In the JavaScript editor, enter the following code: this.mailDoc({ bUI: false, cTo: 'your@email.com', cSubject: this.getField('User Info').value, cMsg: 'Your message goes here' });
Replace 'User Info' with the exact name of your form field. Save the script, close the properties window, and test the button to verify the dynamic subject line.

Easily Manage and Fill PDF Forms with WPS Office
WPS Office offers robust PDF editing capabilities, enabling you to manage interactive forms, edit text, and streamline your document workflow seamlessly.
- 1. Install WPS Office: Download and install WPS Office on your computer or mobile device.
- 2. Open your PDF: Launch the WPS PDF tool and open the PDF form you need to process.
- 3. Access Form Tools: Navigate to the 'Form' tab to edit interactive fields, or use 'Fill & Sign' to complete the document.
- 4. Save and Share: Save your filled PDF and share it directly via email from within the application.

Frequently Asked Questions
Can I include multiple form fields in the email subject line?
Yes, you can concatenate multiple field values in your JavaScript using the '+' operator. For example: cSubject: this.getField('FirstName').value + ' ' + this.getField('LastName').value.
Why is the JavaScript button not opening my email client?
This usually happens if there is a syntax error in your script, if the referenced field name does not exist, or if your operating system does not have a properly configured default desktop email client.
Does this dynamic subject method work on mobile PDF readers?
Custom JavaScript actions like this.mailDoc are generally not fully supported on mobile PDF viewer apps. This solution is designed to work efficiently on desktop PDF applications.
Is it possible to auto-populate the email body as well?
Yes, you can use the cMsg parameter in the this.mailDoc script to dynamically pull form field values into the body of the email, following the exact same syntax used for the subject line.




