Jump to content
  • 0

Validate Field before Submit (Submission Form)


ivan77

Question

Hi,

I have field Period on submission form, before submit I want to check the submission base table for those field.

If period : 11-2024 already exist on table for specific email id, I want to show notification and disable / prevent submit

Is it possible to do this and how ?

 

Rgds,

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello @ivan77,

This post can be helpful:

 

1) The idea is to add a hidden Virtual field to check the condition using the SELECT statement.

For example (field names and table name should be replaced with the corresponding names):

CASE 
WHEN EXISTS (SELECT ID FROM Table_Name WHERE Email = [@field:Email] AND Period = [@field:Period])
THEN 1
ELSE 0
END

Is the Email field received from Authentication? 

2) Add the code to the Footer section:

<script>
  document.addEventListener('BeforeFormSubmit', function(event) {

    let virtualField = document.querySelector("input[id*='cbParamVirtual1']").value; // use the corresponding number of the Virtual field
    
    if (virtualField === '1') {
     event.preventDefault();
     alert('This period exsists, choose another one');
    }
    
  })
</script>

Or this version with custom notifications:

<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
  document.addEventListener('BeforeFormSubmit', function(event) {

    let virtualField= document.querySelector("input[id*='cbParamVirtual1']").value;
    
    if (virtualField === '1') {
     event.preventDefault();
     Swal.fire( '', 'This period exsists, choose another one', 'error' );
    }
  })
</script>

If this doesn`t work, please provide more details.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...