How to prevent submission based on the value of form fields

  • ElevenRiversideDrive
    Asked on April 17, 2024 at 3:09 PM

    Hello,

    I created an election ballot using Jotform:

    https://form.jotform.com/ElevenRiversideDrive/Proxy_2024

    At the top of the form are fields that can be automatically completed once an apartment number is inputted as the unique code, example E10A. This autocompletes the shareholder name, number of shares and number of votes.

    The user can cast votes for the 6 candidates listed. The field Total Votes Cast calculates the total number of votes used.

    I don't want the user to be able to submit the form if the value of Total Votes Cast exceeds the value of the Number of Votes at the top of the form. Is there a way to stop the form from being submitted if this happens?

    If we use E10A as an example, the Number of Votes is 1,424. If I cast 300 votes for each candidate, I've used 1,800 votes. I don't want the user to submit the form in this case.

  • Lesther JotForm Support
    Replied on April 17, 2024 at 3:51 PM

    Hi Helen,

    Thanks for reaching out to Jotform Support. Yes, this is possible by using the Show/Hide Field condition to conditionally display or hide the submit button when the value of the fields "Number of Votes" and "Total Votes Cast" doesn't match. Let me show you how:

    1. Add Paragraph field that will display a prompt message that the total of cast votes should not exceed the number of votes. Right-click on this field and then select hide from the options to make it hidden by default. This is optional if you think it's necessary.

    2. Show/Hide Field condition.

    • On the Form Builder page, go to the Settings at the top navigation bar.
    • Open the Conditions tab on the left and select the Show/Hide Field condition.
    • Add a condition that if the vote fields for the candidates are filled out, and if the field "Total Votes Cast" is Greater Than the field "Number of Votes", it will hide the Submit button and it will display the paragraph message prompt that you added in the step above.

    Test my demo form on this link. Clone it to own a copy and be able to see the entire setup. Here's the guide on How to Clone an Existing Form From a URL.

    Let us know if you have any other questions.

  • ElevenRiversideDrive
    Replied on April 17, 2024 at 5:07 PM

    Hi Lesther,

    I tried the demo, but when I entered E10A and clicked on Auto Complete Fields, I got a message Unknown Access Code.

    I was able to successfully add the paragraph that the total of cast votes should not exceed the number of votes. I also made it hidden.

    Below is a snapshot of the condition that I saved to the form. I think it looks right but I'm still running into a problem. If we use E10A as the example, 1,424 is the number of votes the user can cast among the 6 candidates. I tried casting 200 votes for each of the 6 candidates, which is a total of 1,200 votes cast. That number is within the permitted 1,424 votes. However, I can't cast cast more than 1 vote for any candidate without the condition stopping me. The second snapshot shows 2 votes for David Zelman. It won't let me submit the form.

    How to prevent submission based on the value of form fields Image 1 Screenshot 30

    How to prevent submission based on the value of form fields Image 2 Screenshot 41

  • Lesther JotForm Support
    Replied on April 17, 2024 at 5:39 PM

    Hi Helen,

    Thanks for using Jotform. My demo form doesn't have your Excel document uploaded in to the Spreadsheet to Form widget. There's no way for us to get this from your form so I was not able to add that in the demo. But you can manually fill out the field Number of Votes and then cast votes to see the outcome. Also, clone the form and upload your Excel document to test.

    The condition in your form is working. Only that the value of the field "Number of Votes" has comma (,) added, and that results in a string value. The value of the field "Total Votes Cast" is an integer, and when you compare their values, it's not giving the right result.

    To fix this, add a Form Calculation widget to your form. Fetch the value from the field "Total Votes Cast", and this will convert the string to integer. Right-click on it and select Hide from the option, so it will be hidden by default. See the image below:

    How to prevent submission based on the value of form fields Image 1 Screenshot 40

    Edit the condition to compare the data of Total Votes Cast and the Form Calculation Widget. See the image below:

    How to prevent submission based on the value of form fields Image 2 Screenshot 51

    Here's how I test my demo form without using the Spreadsheet to Form widget.

    How to prevent submission based on the value of form fields Image 3 Screenshot 62

    Give it a try and let us know if you have any other questions.

  • ElevenRiversideDrive
    Replied on April 18, 2024 at 10:32 AM

    Lesther,

    Thank you so much for helping me get this form done! Everything works perfectly!

    Be well,

    Helen

 
Your Answer