Jump to content
  • 0

Can the attached file on submission form be retained if I'm prevented from submittin because I missed some fields that are required or have wrong data type?


cordova

Question

Hi,

I have a submission form with a couple of fields that are required (and they should also only accept numbers) along with a file field. The submission works fine, but say, when a user fills out all fields (including the file field) except for one of the number fields (or if i input a text instead of a number in one of the fields), when I hit submit, the page gets reloaded telling me to fill in all of the fields properly (to not leave any fields blank or to input only numbers), which is expected, but I noticed that the file I have attached earlier disappears. Is there anyway to retain the file when the validation arises?

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @cordova,

I have a workaround for this that uses JavaScript. Basically, the user gets prevented from submission when one of the fields is empty or the value is not a number. That way, the page doesnt have to be reloaded for the validation to occur. On Configure Fields of your DataPage, add a Header and Footer, and add this on the Footer:

 

<script>

document.addEventListener("BeforeFormSubmit", function(e){
var field1 = document.getElementById("InsertRecordNumber_1").value;
var field2 = document.getElementById("InsertRecordNumber_2").value;
var field3 = document.getElementById("InsertRecordNumber_3").value;

 if(isNaN(field1) || isNaN(field2)  || isNaN(field3) || field1.length == 0 || field2.length == 0 || field3.length == 0){
alert("Please enter a number on the fields.");
e.preventDefault();


}
else{


}

});

</script>

 

Wherein field1, field2, and field3 are my fields that should only accept numbers and should not be left empty. If you have more fields, make sure to declare them as variables too, as well as add them in the if condition.

 

Here's a sample DP: https://c1hch576.caspio.com/dp/db26a0002b41bede516840a78237

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