Expand my Community achievements bar.

Required Fields before Submittal

Avatar

Level 2

I have a form that has required questions on it.  Before the user submits the form, they need to fill them all out.  Is there a way, if they haven't filled out the correct questions, when they click on the submit button, that a box will pop up that will tell them which questions they missed?

Thanks in advance!

5 Replies

Avatar

Former Community Member

A common technique is to hide the submit button (set presence to 'hidden'), add a second button labeled 'Submit' that does form validation on the click event, and call the click event on the 'real' submit button if validation is successful.

Here is a simple example where I validate two fields. If both fields are not null I call the click event on object 'submitBtn'.

// form1.page1.subform1.callSubmitBtn::click - (JavaScript, client)


if (form1.page1.subform1.firstName.isNull || form1.page1.subform1.lastName.isNull) {

  xfa.host.messageBox("First name and last name are required fields.");

}

else {

  form1.page1.subform1.submitBtn.execEvent("click");

}

Steve

Avatar

Level 2

Is there a way to do this without having to type in all the field names?  My form is over 5 pages long with around 100 different fields.  Some of the fields are also only mandatory if the user checks a previous field.

Thanks!

Avatar

Former Community Member

At the field level you could set the text field type to 'User Entered - Required' to capture null fields. When the submit executes null fields will be highlighted.

For compound validations where there are field dependencies you will have to write script and specify field names. The pain you experience scripting field names is dependent upon your form structure and naming conventions. If field names are globally unique you will have less pain - you can reference the abbreviated name. If field names are not globally unique you will have more pain - you will have to fully-qualify the field references.

Steve

Avatar

Level 2

The problems I'm having with having the fields just set to required is:

  1. I have some checkboxes that I'm setting required if a previous checkbox is checked.  If the previous checkbox is not checked, then the checkboxes are not required.  But the coding I'm using is not working...it still allows the user to submit the form without checking some of the conditionally required checkboxes.
  2. I would like to tell the user which questions they've missed, since I have a lot of radio buttons, and it depends on which version of adobe they are using as far as whether or not the radio buttons will show up as highlighted/required or not.  It's kind of confusing to a user if they aren't allowed to submit because they haven't filled out all the required fields, but they aren't sure which ones are required because they aren't using the same version of adobe that I am.

Avatar

Level 10

You may want to take a look at John Brinkman's validation scripts and exclusion group scripts:

http://blogs.adobe.com/formfeed/2008/12/exclusion_groups_v40.html

It's worth reading the whole series of posts (parts 1-3).

Latest  version of the script objects are in this post (as far as I know):

http://blogs.adobe.com/formfeed/2009/03/a_form_to_design_a_form.html