Expand my Community achievements bar.

Mandatory check box before form submission

Avatar

Former Community Member
I want users to accept my 'Terms & Conditions' statement on an application form before they are allowed to submit it by the e-mail button.



I want to place a required check box which produces an error message and prevents form submission until it is checked.



I have read hordes of the postings but none of the solutions seem to do quite what I want.



Any advice would be gratefully received
8 Replies

Avatar

Former Community Member
Unfortunately, the user interface doesn't let you specify that a check box is mandatory. Therefore, you have to write a little bit of script.



There are two things you have to do:







  1. Make the check box mandatory so that the user can see (if they choose to in Acrobat) that it's part of the set of mandatory fields. (Although this step isn't entirely necessary, it would be considered "good practice".)





  2. Prevent the form from being submitted if the check box isn't checked.







The first part is easy: Use the Script Editor (you can make it visible, if it isn't already, by choosing the
Script Editor item from the Window menu) to specify the check box's Initialize event. Set the event's language to JavaScript and specify the following code:



this.mandatory = "error";

this.mandatoryMessage = "Must accept terms and conditions before submitting!";


Of course, you can use whatever error/notification message you would like...



At this point, you have a check box which is mandatory once the form is loaded.



The second part is a little tricky. The problem here is that even though the check box is mandatory, clicking the email submit button will still work (!). Unfortunately, you can't use the email submit button's PreSubmit event to prevent the submission either (!). The solution, in this case, is to hide the email submit button (set the Presence property on the Object palette, while the email submit button is selected, to "hidden (exclude from layout)") and place a fake submit button (a normal button object with the caption set to "Email Submit", for example) where the email submit button should be.



Once you've done this, you'll need to add script to the fake submit button which will check the value of the mandatory "terms and conditions" check box. If the value is "1", the user has checked the box and you can fire the hidden email submit button's Click event to get the form to submit. Otherwise, you can show an error message informing the user that they must agree to the terms and conditions before submitting.



The following JavaScript script on the fake submit button's Click event will accomplish this (here, the "terms and conditions" check box is named "CheckBox1" and the hidden email submit button is named "EmailSubmitButton1"):



if (CheckBox1.rawValue != "1")

{

xfa.host.messageBox("Terms and conditions must be accepted prior to submitting!");

}

else

{

EmailSubmitButton1.execEvent("click");

}




Stefan

Adobe Systems

Avatar

Level 1

Hi,

I used the script you provided in the above post, and it worked perfectly, but my situation is a little different: I have two checkboxes, but I only want the message to appear if one of them isn't selected. If the other checkbox is selected, I need the fake submit button to go ahead and generate the email to send the form. I'm new to LiveCycle Designer, and I'm unsure of how to correctly use the "if" and "else" javascript. I need the message to appear when clicking the WebExYes checkbox, but I don't want it to appear when the user clicks the IntercallCheckBox.

Here's what my script looks like so far:

if

(form1.subForm1.WebEx.WebExYes.rawValue != "1"){

xfa.host.messageBox("You must read the FHEG WebEx Usage Standards and select the Yes checkbox before submitting.");

}

else

{

SubmitButton.execEvent("click");

}

if

(form1.subForm1.AccountRequest.IntercallCheckBox.rawValue != "1")

else

{

SubmitButton.execEvent ("click");

}

Can someone tell me what I'm doing wrong or if I can even make this happen?

Thank you,

Hannah

Avatar

Level 1

I figured it out (well, someone I work with who has javascript knowledge did ). Here's the script:

form1.subForm1.Button1::click - (JavaScript, client)

if

(form1.subForm1.AccountRequest.IntercallCheckBox.rawValue == "1") // 1 is checked 0 is not

{

SubmitButton.execEvent ("click");

}

else if (form1.subForm1.AccountRequest.WebExCheckBox.rawValue == "1")

{

if (form1.subForm1.WebEx.WebExYes.rawValue == "1")

{

SubmitButton.execEvent ("click");

}

else

{

xfa.host.messageBox("You must read the FHEG WebEx Usage Standards and select the Yes checkbox before submitting.");

}

}

else

{

xfa.host.messageBox("You must select one of the checkboxes before submitting.");

}

Avatar

Former Community Member

I am sorry to say that i get the error message regardless if the check box is ticked or not

Any clues?

Paul

Avatar

Level 5

I know this thread is old, but just for future visitors.....

If you want to require one of two checkboxes be marked before submitting, you can simplify the above with code like this in the "dummy" button.  The "dummy" button should be visible, "Regular" control type, and contains the script.  The "real" button is hidden, "Submit" control type, and has no script.

if ((checkBox1.rawValue == "1") || (checkBox2.rawValue == "1" )) {

     SubmitButton_Real.execEvent ("click");  // the "real" button is the hidden one

}

else {

     xfa.host.messageBox("Please check one of the above boxes.");   

}

Avatar

Former Community Member
Stefan



Thank you very much indeed, works perfectly !!

I have no scripting experience, where can find out about these tricks ?



Regards

Nigel

Avatar

Former Community Member
You're welcome!



You can find information in these places:







  • Designer Help Topics: "Creating Calculations and Scripts", "Object Scripting Reference", "FormCalc User Reference".





  • These forums.





  • The
    Adobe LiveCycle Designer Developer Center which has documentation on the XFA Scripting Model as well as the Acrobat Scripting Model and which also has a great collection of form samples which show you some of the "tricks of the trade" with respect to building XFA Forms.







Stefan

Adobe Systems

Avatar

Level 1

I'm having the same issue, I want to create the mandatory checkbox, and I've followed the instructions set forth but I'm so new to this that I'm having trouble. Is there a way I can e-mail my document to someone and have them take a look to see what I've done wrong? I'd appreciate any help I can get. Thank you.