This topic is locked
[SOLVED]

 How, with the click of a button, trigger the add a record and print the data?

1/12/2020 4:11:02 PM
PHPRunner General questions
fhumanes author

Hi:
Using a more standard PHPRunner, how could you add a new record in the database and at the same time produce a print page with the newly added data?
Attached image of the type of button.


Thank you all for your contributions.
Regards,

A
acpan 1/12/2020

Try this, this is how i do it using the PDF API:
We are going to pass the new key id after record added to the list page to trigger the PDF API to open the PDF automatically.


  1. Use the default save button that comes with the add page, instead of insert a custom button.

    name it as "Save&Print".
  2. In the after record added event, add this code:



// save the newly added primary key value to be posted to the list page later.

$new_key = $keys["your_table_primary_key_field"];
//Popup a message if needed: "Click Ok to print"
// Redirect to list page with the key value after add

header("Location:your_table_or_custom_view_list.php?new_key=$new_key");

exit();
// Note: if for security reason, you can use session variable instead

// of passing the value in the URL above.


3. In the list page, before process event, add this code:



// Check if new_key is passed, if it is not, set to -1 so that Javascript will ignore it later.

$new_key = isset($_REQUEST["new_key"]) ? $_REQUEST["new_key"] : -1 ;

$pageObject->setProxyValue("proxy_new_key", $new_key);
// Note: If you use session variable to pass the key value, you must unset your session variable here

// after you assign the session value to the Javascript Proxy Variable.


4. In the List Page's Javascript on load event:



var array_new_key = new Array();

array_new_key[0]= proxy['proxy_new_key'];
if ( proxy['proxy_new_key'] != -1 )

{

var params = {

table: 'your_table_or_custom_view_name',

pageType: 'view',

page: 'view',

keys: array_new_key

}

// open the PDF for printing

Runner.PDF.open(params, pageObj, window );

// OR download to PC

// Runner.PDF.download( params );

}


Note:

your_table_or_custom_view_name is the database table name OR custom view you create at PHPRunner's Tables Section.
Hope it helps.
ACP

fhumanes author 1/13/2020

Thank you.
My idea was to display an HTML page for the user to print.
I will try this alternative PDF document.
Regards,

Admin 1/13/2020

Maybe simply save the record and redirect the user to the View page so they can print it?

A
acpan 1/13/2020

Yes, redirect to view page if you want html and it will be even simpler.
Insert a snippet to the top of your view page:



echo '<button id="printButton" onclick="window.print()">Print</button>';


Go to the Editor, custom CSS and insert CSS to hide the button on the print output:



/* hide Print button */

@media print {

#printButton {

display: none;

}

}

/* hide Print button */


After record added event:



$new_key = $keys["your_new_key_id"];

$url = "your_view_page.php?editid1=$new_key";

header("Location: $url");

exit();
fhumanes author 1/13/2020

Thank you very much to all.
Regards,

C
charlesfolder 1/20/2020

Use window.print();