Expand my Community achievements bar.

Redirect with required fields

Avatar

Level 2

I've attached a javascript redirect (which launches a download) at the click event of my "submit by email" button on a form. However, I also have required fields for this form. Should a user not complete those required fields, but still click "submit by email", the redirect will occur (launching the download), but it'll prompt them to complete the required fields before it'll submit the form by email. Is there a way to fix this or do I just need to scrap the whole required fields function?

3 Replies

Avatar

Level 10

If you are using the default "Email Submit Button" it should not let you continue if there are required fields.

If you are using your own email button, you can script to execValidate() with an if statement which will only procede if the required fields are completed.

With execValidate() you can test the whole form or just a subform if all your required fields are in the subform, or individual fields:

if (form1.execValidate()){

     do  action;

}

else {

app.alert("There are fields that need to be filled out before submitting.");

//not sure if relayout() needs to be here or not...can't remember why I put it in now!

xfa.layout.relayout();

//turn on field highlighting in case it's off

app.runtimeHighlight = true;

}

Avatar

Level 2

I am using the preset Submit By Email button and I've attached this script to the postSubmit event:

app.launchURL(http://www.arboroaks.com/heatcontroller/looplogixinstall.exe);

They the user fails to complete the required fields, they get a message stating such, the email will not be sent, but the URL is launched. Is there a better script?

Avatar

Level 10

I think the problem with putting the script on postSubmit is that after the button is clicked that code is going to run anyway. It has no way of knowing that it isn't supposed to run.

You may want to script your own email button - there are lots of examples here in the forums. Unless someone here knows how to fix up the default button. You would put the code in the "do action" section of the script I posted.

You may  also be able do it with your existing submit button hidden and put a button that runs the script I gave you above, which would then click the submit button for you if validation passes. You can use ButtonName.execEvent("click"); to click the submit button.