You are viewing limited content. For full access, please sign in.

Question

Question

Cancelling print dialog from html print button submits form

asked on June 1, 2020

So this one's kind of weird, but I've confirmed it in two environments, one running Forms 10.4.0 and one running Forms 10.4.2.  I've created a custom HTML print button on my form (Code from here https://answers.laserfiche.com/questions/119766/print-form).  When you click the button, it brings up the print dialog as expected, but if you cancel the dialog, it auto-submits the Form.  If i hit the print button from the browser itself and cancel the dialog it does not auto-submit the form.  

 

Does anyone know how or why this would be happening?  I've tried a couple variations of code to print the form, and both do this.  Any ideas on how to make it not submit after cancelling the print dialog?

 


<button onclick="myFunction()">Print Page</button>
<script>
function myFunction() {
    window.print();
}
</script>

or

<button onclick="javascript:window.print()" class="btn-print">Print Form</button>

 

0 0

Answer

SELECTED ANSWER
replied on June 1, 2020 Show version history

Jared's is the correct answer, because as he mentioned the built-in print functionality is probably going to give a much better looking result.

However, to explain the behavior you're seeing, the reason your "print" button is submitting the form is that you have not assigned a type to the button element.

When an HTML button is added without a type attribute, browsers will interpret it as a Submit button by default, so you should always set a type. https://www.w3schools.com/tags/tag_button.asp

Adding type="button" should correct that behavior.

The most likely reason it doesn't submit until after you cancel the dialog is that the browser is just waiting for the dialog to go away, much like it would if you triggered an alert().

1 0

Replies

replied on June 1, 2020

In Forms 10.4.1, we introduced the print button on each form so you could print a copy of any in-progress or completed form. That would work better, no? If you can upgrade to the 10.4.2 version, that should be your best bet. 

Using the general browser's print function can lead to sub-optimal results due to the way we build the forms/tasks page. Our print will make sure to get the full form. 

2 0
replied on June 1, 2020

I'm unable to find any built-in print form button.  Are you referring to the Print button that displays on the thank you page/during a user task?  If so, that is not an option, as this Print function on this form is to workaround an issue we have with the adoption of this digital process, in that some users who are not as tech savvy as others will need a semi-blank version of the form printed that they can write on, and someone can transcribe back into forms later.  

 

But i did try out the fix of assigning the button type="button" and that did work as intended.  Thank you for you're help.

 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.