This topic is locked

How to create multiple print pages based on the same data

12/8/2010 12:49:34 PM
PHPRunner Tips and Tricks
Sergey Kornilov

Let's say you need to allow your users to print several different document types based on the same data i.e. invoice and order receipt. It would be useful if you can select a few records on the list page and click 'Print selected' button choosing required document format.


This tutorial explains how you can create additional 'print selected' buttons to print document in another format.
1. Create custom view for your table on the "Datasource tables" tab, enable print page for this custom view and modify this page appearance in Visual Editor.
2. Create new button on the list page of your main table on the Visual Editor tab.

You can use custom event ("Insert PHP code snippet" option) to create this button. Here is a sample code:

echo "<SPAN class=buttonborder><INPUT id=print_selected2 class=button value=\"Print invoices\" type=button name=print_selected2></span>";


3. Add event for this button in the "List page: JavaScript OnLoad" event on the Events tab:



var submitUrl = "CustomView_print.php";
//replace CustomView with the actual custom view name
if (typeof id == "undefined"){

id = this.id;
}
pageObj = this;

$("#print_selected2").unbind("click").bind("click", function(e){

var selBoxes = $('input[@type=checkbox][@checked][@id^=check'+id+'_]');
var form = new Runner.form.BasicForm({

standardSubmit: true,

submitUrl: submitUrl,

method: 'POST',

target: '_blank',

id: pageObj.id,

baseParams: {"a": 'print'},

addElems: cloneElements(selBoxes)

});
form.submit();

form.destructor();
});
J
Jane 1/17/2012

Here is the corrected code for 'List page: JavaScript onload' event for PHPRunner 6.0:

var submitUrl="CustomView_print.php";

if(typeof id=="undefined"){id=this.id;}
pageObj=this;

$("#print_selected2").unbind("click").bind("click",function(e){

var selBoxes = pageObj.getSelBoxes(pageid);

var form=new Runner.form.BasicForm({

standardSubmit:true,

submitUrl:submitUrl,

method:'POST',

target:'_blank',

id:pageObj.id,

baseParams:{"a":'print'},

addElems: pageObj.cloneFormElements(selBoxes)

});
form.submit();

form.destructor();

});
R
rlarkinsmith 2/22/2013

Can't seem to make the updated version for 6 work. When I click on my button, it only runs the bottom event. There are 2 different forms that I want to print. I had this working in 5.3, I know it is something simple, just don't know what it is.

C
corsor 10/8/2013

Hello,the code for me is not working, i have phpr 5.3 and the i have a custom view created with two joined tables on the print page , when i push the print button it´s going to the custom print page that i created but is not passing no parameter from the master page the print page is going blank,anyone know why?

Thanks in advance

Regards

C
corsor 10/8/2013

Hello, my mistake working ok .

Regards

romaldus 10/9/2013

can i use this in a view page?

Sergey Kornilov 10/15/2013

Yes, you can use the same approach with View page. It's even easier in fact, you do not need any code supplied in bullet #3. Just point the user to another view supplying different URL. No need to create the form and post data.

romaldus 11/22/2014

i tried to use report page as submitUrl. When i print selected record on list page, all records in the current table appears in report page , not selected record with the same ID.

M
mrcaseyman 1/13/2016

I have this working to create one second print page.

What do I change if I want to have say three or four different print pages please?

M
mrcaseyman 1/13/2016



I have this working to create one second print page.

What do I change if I want to have say three or four different print pages please?


I figured out something that works.
I moved ; down into the function for each different one.