• Resolved s

    (@sdnazdi)


    Hi,
    I asked in some question some month ago about viewing the results of a form.
    In that question you replied that to view inserted data, I can create pagination and in the second page I have to insert HTML field and the corresponding fields inside that HTML.

    Now I like to add a print button at the bottom of that HTML field to print that preview results. I used the code taken from here
    https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_print
    it works when I use the PREVIEW inside forminator dashboard, however when I save it and use the shortcode of the form in a WP page, that button shows up, but does not work.
    If you can help me to solve this question, I also like to hide the button when I print?

    If my question is not clear, please let me know.
    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @sdnazdi,

    I hope you are doing good today.

    Can you please share a URL where we can see this form so we can check and try to help you?

    We look forward to hearing back from you.

    Kind Regards,
    Nebu John

    Thread Starter s

    (@sdnazdi)

    Hi
    Thanks, the link is here:
    https://mywpsdemo.ir/project/form/

    Hi @sdnazdi

    It looks like on the frontend, the plugin is stripping the “onclick” tag on your button.

    I see a previous thread that demonstrates the same issue. I’m guessing this hasn’t been patched yet.

    In the meantime, you can add this javascript snippet to any page containing that specific form, and it will add the correct onclick attribute to the print button.

    <script>
    document.querySelector("div#forminator-custom-form-403--page-1 button").onclick=function(){window.print()};
    </script>

    (Note: For some reason, clicking the print button also seems to trigger the submit button, looking into that too)

    Hope this helped

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @sdnazdi

    The code is indeed “stripped out” for a safety/security reasons to prevent any possible JS-based attacks.

    It actually is a HTML field also so it is not really expected to include JS scripts (which is not HTML).

    The solution and an always-recommended-practice is to use scripts separately. Aside from enqueueing script from separate file, the two simplest solutions here would be:

    1. The solution that @aakash8 (thanks for jumping in again!) suggested above; note: to add such code you can use one of the “code snippets” plugins freely available at www.ads-software.com

    2. or to make it even more universal:

    – create an empty file with .php extension (e.g. “form-printer.php”)
    – copy and paste this code into it:

    <?php 
    
    add_action( 'wp_footer', 'forminator_preview_printer' );
    function forminator_preview_printer() {
    	
    	?>
    	<script>
    	jQuery(document).ready(function($) {
    		setTimeout(function() {
    		$('.formprinter').click(function() {
    			window.print();	
    		});
    		}, 1000);
    	});	
    	</script> 	
    	
    	<?php 
    	
    }

    – save the file and upload it to the “/wp-content/mu-plugins” folder of your site’s WordPress installation

    Now you can add this HTML to the HTML field (any one, of any form, not even Forminator forms) or, in fact, to any post or page or anywhere on the site (outside the form too):

    <span class="formprinter">PRINT ME</span>

    Best regards,
    Adam

    Thread Starter s

    (@sdnazdi)

    Hi @wpmudev-support8,
    Thanks.
    I created a php file and copied it to “/wp-content/plugins”
    Then for testing, I created a new page in WP (also a new form with a separate HTML page), and paste the span tag in the editor (text), but I do not see any button for printing. Even I changed the span tag to button, but it does not do anything.

    -Do I miss something? I will appreciate if you can explain a little bit more.
    I tried also
    <button onclick="window.print()"><span class="formprinter">PRINT ME</span></button>
    or
    <button onclick="forminator_preview_printer()"><span class="formprinter">PRINT ME</span></button>
    and when I click on the button then the form is submitted(no printing notification).
    -what is the following code at the end of your code above:

    <?php 
    	
    }
    

    Is it correct or something missing?
    Thanks.

    • This reply was modified 2 years, 2 months ago by s.
    • This reply was modified 2 years, 2 months ago by s.
    • This reply was modified 2 years, 2 months ago by s.
    • This reply was modified 2 years, 2 months ago by s.
    • This reply was modified 2 years, 2 months ago by s.
    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello there @sdnazdi

    The button should not have anything “onclick” as the snippet above should do the trick, so it should be something simpler like:
    <button class="formprinter">PRINT ME</button>

    The code looks good, the opening PHP tag in the end is required as there was a closing tag before.

    Take care,
    Dimitris

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘print preview of output’ is closed to new replies.