How to Validate Required Fields Before Saving or Printing a PDF Form
Question details
The user wants to ensure all required fields in a PDF form are completely filled out before allowing the document to be saved, printed, or submitted.

- Product
- Device & OS
- not provided
- Scenario
- Distributing a fillable PDF form that requires specific data fields to be completed by the recipient.
- Observed behavior
- By default, checking the "Required" property on a field does not prevent users from saving or printing an incomplete PDF form.
Ensure your PDF editor supports JavaScript and allows you to modify form field properties and document-level actions.
Implement JavaScript Validation on a Custom Submit or Print Button
Use a custom script attached to a button to check for empty required fields and prevent the submission or printing action if any are missed.
The most reliable way to enforce field validation is to hide the default print/save menus if possible, and force users to click a custom button to submit or print the form. This button can run a JavaScript check prior to executing the action.
Right-click the targeted form fields, select Properties, and check the 'Required' box under the General tab.
Add a new button to your PDF document labeled 'Submit' or 'Print'.
Open the button's Properties, go to the Actions tab, choose 'Run a JavaScript' from the Select Action dropdown, and click Add.
Enter a script that loops through the required fields. If it finds empty values, configure it to display an error alert to the user and stop the print or submit action.

Use Document-Level Scripts for Pre-Save and Pre-Print Events
Automatically trigger a validation script when the user selects File > Save or File > Print from the standard menu.
Create and Manage Fillable PDF Forms with WPS Office
WPS PDF provides comprehensive tools to create, edit, and manage fillable forms easily. You can add text fields, checkboxes, and set required properties without complex programming.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the form creation and editing tools.
- 3. Insert Form Fields: Click on the desired field type (Text Field, Checkbox, etc.) and click on the document to place it.
- 4. Configure Properties: Double-click the inserted field to open the properties panel, where you can easily mark it as a required field.

Frequently Asked Questions
Why doesn't the 'Required' property stop saving by default?
The 'Required' property in most PDF editors only flags the field visually or blocks standard submit actions. It does not inherently intercept the system's File > Save or File > Print menu commands without additional JavaScript.
Can I validate checkboxes and radio buttons the same way as text fields?
No. Checkboxes and radio buttons use different value states (such as 'Off' or specific export values) instead of an empty string, so your JavaScript must check for their specific unchecked states.
Will JavaScript validation work on mobile PDF readers?
Mobile PDF readers often have limited or no support for JavaScript. Validation scripts may not execute properly on smartphones or tablets, meaning users might still be able to save or submit incomplete forms from mobile devices.
How do I highlight missing fields for the user?
Within your JavaScript validation loop, you can dynamically change the fill color or border color of empty required fields (for example, to red), making it easier for users to spot what they missed before attempting to save again.




