Print data

azz13 28 Apr, 2012
Can I print only table created with custom code action (not all page)
GreyHead 28 Apr, 2012
Hi azz13,

Please explain more, I don't understand your question.

Bob
azz13 02 May, 2012
I create simple form to show multiple row data to the table as described in tutorial. All works great. I want add print button like Joomla article to allow users send this table to printer.
GreyHead 05 May, 2012
Hi azz13,

Here's one way to add a print button to a a ChronoForms Thank You page.

In the Thank you page wrap the section that you want to print in div tags:
<div id='print_div'>
. . . 
</div>

Add this button code to the page where you want the button to appear (probably outside the 'print_me' div).
<input type="button" value="Print" id='print_button' style='visibility: hidden;'></input>
Note that the button is invisible if the User doesn't have JavaScript enabled so that they don't see a print button that they can't use.

Add Custom Code action to the On Submit event and add this code to it:
<?php
$doc =& JFactory::getDocument();
$script = "
function printPage()
{
    var html, css, csss_file, printWin;
    css = \"\";
    css = \"<style type='text/css'>\"+css+\"</style>\";
    css_url = '';
    if ( css_url !== '' ) {
        css_url = \"<link rel='stylesheet' type='text/css' href='\"+css_url+\"' media='print' />\";
    }
    html = '<html><head>'+css+css_url+'</head>'+$(id).innerHTML+'</html>';

    printWin = window.open('', '', 'left=100, top=100, width=600, height=400, toolbar=0, scrollbars=0, status=0' );
    printWin.document.write(html);
    printWin.document.close();
    printWin.focus();
    printWin.print();
    printWin.close();
}
var id;
window.addEvent('domready', function() {
    id = 'print_div';
    $('print_button').setStyle('visibility', 'visible');
    $('print_button').addEvent('click', printPage);
});
";
$doc->addScriptDeclaration($script);
?>

Save and test.

Notes: The code allows for you to add CSS styling by linking to a CSS file or adding some CSS directly to the css = \"\"; line.

If you prefer an image instead of a button use
<input type='image' src='media/system/images/printButton.png' id='print_button' />


Bob
azz13 08 May, 2012
Thanks for help. All working good.
There is one errror
<div id='print_me'> in Thank you page and id = 'print_div'; in Custom Code should be the same
GreyHead 12 May, 2012
Hi azz13,

Sorry about my typo, I fixed my earlier post.

Bob
ichakhy 09 Dec, 2012
first i'm so sorry for my question, bcuz maybe it sounds so stupid. i'm new in joomla.
So can u explain where can i find the "On Submit Event"??
i don't understand this sentence : 'Add Custom Code action to the On Submit event and add this code to it:'
GreyHead 12 Dec, 2012
Hi ichakhy,

Please take a look at the Video tutorials linked from this FAQ that should help you understand a bit more. There's another written tutorial on Events and Actions linked from this FAQ

Bob
kate_ee 28 May, 2013
Hi Admin,

I have just followed your instructions and made a print button on the "Thank Message" screen.
It is working very good when I enable the "Login" module.
But I don't want the "login" menu on my form, so I disable it.
After that the print button doesn't show up until I enable the "login" menu again.

Please you advise.

Regards,

Lily
GreyHead 30 May, 2013
Hi Lily,

There is no reason I can think of why the Login module would affect the print button. Please post a link to the form so I can take a quick look.

Bob
kate_ee 01 Jun, 2013
Hi GH,
Thank you for you reply, but the form is built on a testing server which can't be accessed by outsider.
I finally know that if you use the template beez5, it will happen. Could you please look into that?

Thanks again

Regards,

Lily
GreyHead 01 Jun, 2013
Hi Lily,

Please check and see if the MooTools library is being loaded on your page. I suspect that may be the difference.

Bob
kate_ee 08 Jun, 2013
Could you tell me how to check it out ?

regards,

Lily
GreyHead 08 Jun, 2013
Hi Lily,

Look at the list of files in the page header when you view the page source. Or better, click F12 in your browser to access the web developer tools and look at the Sources tab.

Bob
kate_ee 10 Jun, 2013
Hi Bob,
I installed the joomla v3.0, and did the same thing on it, it worked fine. So, I think it is joomla v.31 bugs again. Joomla v3.1 is TOO BAD !

Thank you for your attention.

Regards,

Lily
This topic is locked and no more replies can be posted.