• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

How to only submit form if validation passes?

Community Beginner ,
Sep 29, 2020 Sep 29, 2020

Copy link to clipboard

Copied

I am hoping to add some validation in to check whether certain fields are null if some are filled out. Unfortunately just using the required field isn't enough for this as I don't want to always make it mandatory, I just want to make certain fields mandatory if some are filled out. For example: 

 

Email Address

Description

Both of the above fields are optional, however if a description is entered I want to validate that there is also a value for Email Address on submitting the form. I have this part of the script complete I believe.

 

I am hoping for some assistance on how to only submit the form if the validation passes. At the moment I have it set up as two different mouse up actions (Run a Javascript & Submit a Form) meaning that they're independent of eachother and it still submits the form even when the validation fails and an alert is brought up. So I am seeking help in writing the submit a form logic in my JavaScript file if anyone can lend a hand. 

TOPICS
Acrobat SDK and JavaScript

Views

90

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 29, 2020 Sep 29, 2020

Copy link to clipboard

Copied

Is the submit action configured to submit by email or to a web server? In any case, you'd just have to use the equivalent JavaScript method (e.g., submitForm) and not use the submit form action. In your scipt, you'd check the fields, and if everything's OK, allow the submit to take place, and otherwise don't.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2020 Sep 29, 2020

Copy link to clipboard

Copied

LATEST

Basically you would use something like this:

 

var condition1 = ...;

var condition2 = ...;

var condition3 = ...;

if (condition1 && condition2 && condition3) this.mailDoc({cTo: "me@server.com"});

else app.alert("You must first do X, Y and Z before submitting the form.",1);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines