I figured it out! Here was the solution:
I wrapped my two buttons (Submit and fake submit) in a subform called "buttons". (Without wrapping them in the subform the functionality still worked but the buttons ended up at the top of page 1 instead of at the end of the form.)
Then I put this Javascript in the layout:ready event of SubmitButton1 (the real submit button):
if (xfa.layout.pageCount()>3) {
Page1.buttons.SubmitButton1.presence = "hidden";
}
else {
Page1.buttons.SubmitButton1.presence = "visible";
}
And I put this Javascript in the layout:ready event of SubmitButton2 (the fake submit button):
if (xfa.layout.pageCount()>3) {
Page1.buttons.SubmitButton2.presence = "visible";
}
else {
Page1.buttons.SubmitButton2.presence = "hidden";
}
The presence of both buttons is set to "Hidden" in the Object - Field tab.
On the click event of SubmitButton2 I have this JavaScript:
xfa.host.messageBox("Per the instructions on page 1 of this form, this document must be no longer than 3 pages. Please delete some text from the document before you submit it so that it is 3 pages or less or else it will be rejected."
, "Exceeded Allowed Number of Pages", 1);