How to Validate Required Fields, Lock PDF Forms, and Send Email
Question details
The user wants to use JavaScript in a PDF to validate required fields, make the form read-only upon completion, and automatically email it with a dynamic subject.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires validation and automated email submission.
- Observed behavior
- The user needs a script to check for empty required fields, halt submission if incomplete, or lock the document and trigger an email if successful.
Ensure you have access to Adobe Acrobat Pro or a similar advanced PDF editor that supports document-level and button-action JavaScript, as well as a default email client configured on your device.
Using Adobe Acrobat JavaScript to Validate, Lock, and Email
Add a custom JavaScript action to a submit button that checks required fields, locks the form, and triggers an email client.
This method involves creating a custom script attached to a form button. The script iterates through the form fields, checks if required ones are empty, displays an alert if any are missing, and if all are filled, sets them to read-only before calling the mailDoc function.
Open your PDF in Adobe Acrobat, enter Prepare Form mode, and add a Button field to your document where users will click to submit.
Right-click the button, select 'Properties', go to the 'Actions' tab, choose 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'.
In the JavaScript Editor, write a script to check for empty fields. Use an array of required field names and loop through them, using if(this.getField('FieldName').value == '') to detect missing data and alert the user.
Add logic to the script so that if the validation passes, it loops through all fields and sets this.getField(fieldName).readonly = true to lock the form.
Finally, append the mailDoc method to the successful branch of your script: this.mailDoc({bUI: true, cTo: 'email@example.com', cSubject: this.getField('SubjectField').value}); to attach the locked PDF to an email.

Easily Manage and Edit PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily view, fill out, and manage interactive PDF forms without needing heavy software.
- 1. Open WPS PDF Editor: Launch WPS Office and navigate to the PDF Editor tool from the home screen.
- 2. Open Your PDF Form: Click 'Open' and select your interactive PDF form document to load it into the workspace.
- 3. Fill the Form: Click on the highlighted form fields to enter your data smoothly.
- 4. Protect and Share: Use the 'Protect' tab to add restrictions if you want to prevent further editing, then click the 'Share' or 'Email' button to send the document.

Frequently Asked Questions
Why isn't the mailDoc JavaScript function working in my PDF?
The mailDoc function may be blocked by the security settings of the user's PDF viewer. Ensure that JavaScript is enabled in the application's trust settings, and note that browser-based PDF viewers often do not support this function.
How can I check required fields without writing JavaScript?
In the PDF form editor, you can right-click a text field, select Properties, and check the 'Required' box under the General tab. The PDF reader will automatically prompt the user if they try to submit the form while this field is empty, without needing custom code.
Can I make only specific fields read-only instead of the entire form?
Yes. In your JavaScript, instead of looping through all fields, you can specify exactly which fields to lock by using this.getField('SpecificFieldName').readonly = true; after the validation check passes.




