Skip to main content
smb1204
Participant
November 6, 2020
Question

Required fields in fillable .pdf

  • November 6, 2020
  • 2 replies
  • 1551 views

I have a form that was created in InDesign that we are saving as a fillable .pdf. There are different required fields thru out the form. Is there any way to stop the form from being saved or submitted if all the required fields are not completed?

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
November 6, 2020

While you can't stop the form from being saved (or printed), you can force the saved copy to be blank.

You would need to use a script to do that, like this (paid-for) tool I've created:

http://try67.blogspot.com/2011/12/acrobat-validate-fields-before-printing.html

You can also get it from my new web-site, where's there's currently a "soft launch" sale:

https://www.try67.com/tool/acrobat-validate-required-fields-before-printing-or-saving

The discount code is available on the front-page.

Bernd Alheit
Community Expert
Community Expert
November 6, 2020

You can't stop the save of the form. You can only display a message when not all required fields are filled.

Participating Frequently
August 12, 2024

How would I go about creating this error message for grouped checked boxes? I found a way to do it if the textbox isnt completed but I also need it for grouped questions where only one selection is needed. I have this code, that gives an error when the text box isn't completed but it won't give the error when only the checked boxes are skipped over. 

function validateFormFields() {
// Define required text fields (if any)
var requiredTextFields = ["TextField1"]; // Replace with actual text field names

// Define groups of checkboxes where at least one must be checked
var checkboxGroups = [
["CheckboxGroup1_Option1", "CheckboxGroup1_Option2"], // Group 1: At least one must be checked
];

var allTextFieldsValid = true;
var allCheckboxGroupsValid = true;
var invalidMessage = "";

// Check individually required text fields
for (var i = 0; i < requiredTextFields.length; i++) {
var fieldName = requiredTextFields[i];
var field = this.getField(fieldName);

if (!field || field.value.trim() === "") {
allTextFieldsValid = false;
invalidMessage += "Please complete all required text fields.\n";
// Note: Do not break here so we can check all fields and all checkbox groups
}
}

// Check checkbox group requirements
for (var j = 0; j < checkboxGroups.length; j++) {
var group = checkboxGroups[j];
var groupValid = false;

for (var k = 0; k < group.length; k++) {
var checkboxName = group[k];
var checkbox = this.getField(checkboxName);

// Check if checkbox is checked
if (checkbox && checkbox.value !== "Off") {
groupValid = true;
break; // Exit loop if at least one checkbox in the group is checked
}
}

if (!groupValid) {
allCheckboxGroupsValid = false;
invalidMessage += "Please select at least one checkbox in each required group.\n";
// Note: Do not break here so we can continue checking other groups
}
}

if (!allTextFieldsValid || !allCheckboxGroupsValid) {
app.alert(invalidMessage);
return false; // Prevent saving if any validation fails
}

return true; // Allow saving if all validations pass
}

// Add the save event trigger
this.setAction("WillSave", "if (!validateFormFields()) { event.rc = false; }");

try67
Community Expert
Community Expert
August 13, 2024

The error message about the check-boxes appears fine for me. However, it's not set up very well.

For example, if you have multiple missing text fields you'll get the same line over and over. Same for the check-boxes. It's better to include the actual field name (or description) in the error message, and only show the title text once.