Jump to content
  • 0

Validate a code


imJihyo

Question

Hi there! It's me again :D

I just wanted to ask for suggestions on how I can create a validation type of form. Basically, my payment committee generates payment confirmation codes after a customer pays for their subscription. The customers then fill out a form that contains basic information about them such as name, amount of payment, a checkbox that they agree to the terms and conditions, and their payment confirmation code. What I want to happen is when they try to submit this form and the payment code is invalid, they will not be able to submit the form. 

Additionally, I do have a separate table that contains the payment confirmation code along with the customer's name and date when it was generated.

Will appreciate any suggestion :wub:Thanks!!  

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hey there @imJihyo!

Maybe you can use a calculated field to check if the code is valid OR existing inside your code table, then use JavaScript to prevent the submission? 

I created one DataPage for creating payment confirmation codes. This one makes you enter the name of the customer then it generates a random ID as the code:

image.png.c552e30cc07daffbf56877ad26c97b7d.png

Then, for the form that the users will fill out, I used a combination of calculations and JavaScript. 

Here's the calculation (you can use a virtual field, set the form element to calculated value, then use the solutions here to hide the field):

NOTE:

- change PaymentCode inside count and beside WHERE to the field name of your code inside your code table

- change CodeTbl to the name of your table that contains the code

- PaymentCode inside [@field.PaymentCode] to the field name of where your users will enter the code for validation

CASE
WHEN (SELECT COUNT(PaymentCode) FROM CodeTbl WHERE PaymentCode = target.[@field:PaymentCode]) = 1
THEN 1
ELSE 2
END

And here's the JavaScript:

NOTE:

- change elements accordingly if needed

<script type="text/javascript">

document.addEventListener('BeforeFormSubmit', function(event) {

var Input1 = document.querySelector("span[id^='cbParamVirtual1']").innerHTML;

     if (Input1 == 2) {
event.preventDefault();

alert('Please Enter a Valid Payment Code!');

} else {

document.forms["caspioform"].submit();

}

});
</script>

 

This is then what it looks like when they enter a non existing/not valid code:

image.thumb.png.1773e21c118a6f830219510d4e5dfead.png

When the entered code is valid, it should successfully submit.

 

I hope this helps!!!

 

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...