Inserted record id

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
sangnandar
User
Posts: 980

Inserted record id

Post by sangnandar »

It's an easy setup.

  • Set return page after add to View Page

After user add a record it will return to View Page, something like:
<table>view.php?showdetail=&id=<this is the inserted record id>
Meaning: the apps knew the value of the just inserted record id.
So there has to be a class/function to access <this is the inserted record id> value, right?
My question is, what are they?

Thanks.


mobhar
User
Posts: 11703

Post by mobhar »

Try put this code in "Row_Inserted" server event, does it return the valid value?

$this->setMessage("Inserted ID: " . $rsnew["id"]);


sangnandar
User
Posts: 980

Post by sangnandar »

It does. :)
Thanks.


sangnandar
User
Posts: 980

Post by sangnandar »

Here's the thing.

Row_Inserted()
$_SESSION["myid"] = $rsnew["id"];

Add Page, client side:
.onClickSomething
window.open(<url containing $_SESSION["myid"]>);

I'm about to try server events or ajax or else to send $_SESSION["myid"] to add page client side but just then I realized, when Row_Inserted() fired the Add Page should already left.
Am I right or wrong?


mobhar
User
Posts: 11703

Post by mobhar »

Use "ew_SetClientVar" function to pass server side data to client side as a property of the ewVar object. Please read "Some Global Functions" under "Server Events and Client Scripts" topic from PHPMaker Help menu for more info.

For your case, try setup "Add Page from "Table" setup -> "Return Pages" -> "After add". In this situation, then when Row_Inserted event is fired, you will redirected back to that same Add Page again.


sangnandar
User
Posts: 980

Post by sangnandar »

I didn't intend to back to the same Add page.

This is what I'm trying to achieve:
When user click submit, I need
.onClickSubmit
window.open(<url containing $rsnew["id"]>);

Here are the problems:

  1. I need a pop up window, not a normal return page.
  2. window.open() is the solution. BUT... when submit button is clicked, $rsnew["id"] is not yet existed, because Row_Inserted() fired AFTER submit button is clicked. Am I right?

mobhar
User
Posts: 11703

Post by mobhar »

Yes, you're right.


sangnandar
User
Posts: 980

Post by sangnandar »

And now I have no idea how to send $rsnew["id"] to client-side.

To simplify the case, here are what I'm trying to accomplish when the Add page submit button is clicked:

  1. On server-side, the return page goes default (i.e List Page). // no problem
  2. On client-side, window.open("<table>view.php?export=print&id=<inserted-record-id>"). // problem of getting <inserted-record-id> value

kirondedshem
User
Posts: 642

Post by kirondedshem »

try saving the id into a session during row_inserted event, then you can access it anywhere, just remember to clear it after use eg
$_SESSION["my_id"] = $rsnew["id"];


sangnandar
User
Posts: 980

Post by sangnandar »

kirondedshem wrote:
try saving the id into a session during row_inserted event, then you can
access it anywhere, just remember to clear it after use eg
$_SESSION["my_id"] = $rsnew["id"];

Already tried that before, didn't work.
Because when the submit button is clicked $rsnew["id"] don't yet existed, because Row_Inserted() event don't yet fired.
When $rsnew["id"] is existed, the Add Page already left.

My temporary silly workaround would be to create a dummypage.php just for redirecting purpose.
.onSubmitButtonClick
window.open("dummypage.php");

dummypage.php
Redirect(<url containing $_SESSION["myid"]>);


sangnandar
User
Posts: 980

Post by sangnandar »

Got it.

sangnandar wrote:
when the Add page submit button is clicked:

  1. On server-side, the return page goes default (i.e List Page). // no problem
  2. On client-side, window.open("<table>view.php?export=print&id=<inserted-record-id>").
    // problem of getting <inserted-record-id> value

Add Page, Row_Inserted()
$_SESSION["myid"] = $rsnew["id"];

On the return page (i.e List Page), Startup_Script
if ($SESSION["myid"]) {
window.open(<table>view.php?export=print&id=$
SESSION["myid"]);
unset($_SESSION["myid"]);
}

This should be the ideal approach.


Post Reply