This topic is locked

Getting a just Entered field to a JavaScript Variable after pressing Save

2/18/2019 4:12:08 PM
PHPRunner General questions
S
stevelewis author

Hi,
I'm looking for a cleaner method to do this:
I have a user table with firstname, lastname and email
I'm on the user Add Screen and I enter the data. When I press "SAVE" I use the Custom Add Event to grab the email and put it in a SESSION variable, then I jump to a dummy Table ADD EVENT.
Code in CustomAdd
$_SESSION["email"=$values["email"];

header("Location: dummy_add.php");

exit()
At the Dummy Table ADD Page Event I can use the Proxy commands with the JavaScript OnLoad Event
In Before Display:
$pageObject->setProxyValue("email", $_SESSION["email"]);
In JavaScript OnLoad Event
var email=proxy["email"];
Now I can process the email JavaScript Variable as needed and then I jump to where I want to really go before the dummy Page Appears.
header("Location: ..._list.php");

exit()
I got all of the above to work but it's sloppy having to setup a Dummy Table to do this. Can anyone suggest a cleaner way to send the newly added email field to JavaScript for processing without having to setup a Dummy Table.
-Steve

admin 2/18/2019

Steve,
what exactly you trying to achieve? I'm sure there is a better way to do this, need to know what your objective is.

S
stevelewis author 2/18/2019



Steve,
what exactly you trying to achieve? I'm sure there is a better way to do this, need to know what your objective is.


I ask the user for their Email with an Add Screen, then want to save their email to local storage which can only be done with JavaScript. I can't figure out how to execute JavaScript after I save the email field of the record from the Add screen. The JavaScript Onload for Add Screen happens before the record is Saved so I did the trick I explained with the dummy table.
This is the JavaScript command I use to save the field to local storage from JavaScript.
localStorage.setItem("ls_email", proxy["email"]);
I would like a cleaner method and would appreciate any thoughts on this.
Thank you,
-Steve

admin 2/18/2019

Do it before record is saved using beforeSave. Here is an example of doing this:

https://xlinesoft.com/phprunner/docs/how_to_ask_for_confirmation_before_saving_record.htm