Cancel sumbit



Description

 

The cancel submit deluge statement is used in the Form Action - Validate block to stop a form from being submitted.

 

Syntax

on submit
  {
  // specify validation code
  {
  // specify alert message if not valid and cancel the submission
  alert "age should be between 20 to 100";
  cancel submit;
  }
		

 

Note:

 

The alert message in 'on submit' will be invoked only in the presence of a 'cancel submit'. In the absence of form cancellation, the alert message is bypassed by Zoho Creator.

 

 

Examples - Free flow Scripting

1. Alerts the message specified in quotes and cancels submission, if the value entered in the age field is not between 20 and 100.

 

 Age
    (
        type  =  number
    )
 on submit
    {
        if (input.Age < 20) && (input.Age >100)
        {
            alert "age should be between 20 to 100";
            cancel submit;
        }
    }

 

2. The code snippet given below fetches the data corresponding to the particular position applied by the applicant and checks if the Status for that position is currently closed and displays an error message to the user. You can access all the details related to that position by accessing the variable “opening”.

 

on submit
   {
     opening = New_Opening [Position_Name == input.Applied_For];
     if (opening.Status == “Closed”)
       {
            alert “The job profile ” + this.Applied_For + ” for which you have applied is not currently open “;
            cancel submit;
       }
   }        

 

Example - Using Script Editor

 

Let us built a Validate action script using Script Builder for the SampleForm1. Click here, to view the SampleForm1. The script will validate the Contact Address field in the SampleForm1. If the Amount is greater than 1000, the Contact Address is mandatory. In other words, if the ContactAddress is not specified for amounts greater than 1000, the form data will not be submitted.

1. Add Validate form action : Click on the Script Tab to display the Script Editor. Select the Form Action On Add -> On Validate as highlighted in the screen-shot below.

 

2. Add If <condition>

a. Drag and drop the If control flow statement, as highlighted in the screen-shot below. Click on Edit to specify the If condition. Refer the If, else if, else topic, for more information on the syntax and usage.

 

 

b. The Edit dialog for If is displayed as shown below, wherein you have to create the If condition.

c. Click Done to add the If condition to the script editor as show below.

 

 

 

3. Add Alert message: Now, we have to add the If statements to be executed, when the If condition is satisfied. In our example, if the Amount is greater than 1000 and if the ContactAddress is not specified, an alert message will be displayed and the form submission will be cancelled.

 

4. Add Cancel Submit: To cancel submission,

 

5. Click Save Script to add the On validate script action to the form definition.

 

6. To view the complete script, select Form Definition -> With Action or select Free-flow Scripting. The validate action script is successfully added to the form definition, as shown below.

 

 

 

SampleForm1

 

When the form data is submitted, if the Amount is greater than 1000 and the ContactAddress is not specified, the alert message is displayed and the form is not submitted, as shown below.