This topic is locked

custom button to insert session variables into fields on add page

4/12/2023 2:54:23 PM
PHPRunner General questions
P
pmuckle authorDevClub member

Hi All,
I can't find the answer to this, maybe it's too simple.
I have two fields location_ID and owner_ID. These are saved as session variables after each record is saved $_SESSION["locationID"] and $_SESSION["ownerID"]
In some cases when a record is added, it would save time to insert the data from the previous record. Not all cases though so I can't set it as a default value.
I have a button on the add page, 'copy previous'.
Can anyone help with the code to insert the variables into the fields.
Thanks
Pete

W
wedi 4/12/2023

I hope I understand what you want.
When adding a record you save locationID and ownerID to a SESSION variable for later use when adding the next record.
With custom button "copy previous" you want to fill out two form fields (locationID and ownerID) on add page with the SESSION values?
If so you can do this as follows:
Let event "Client before" empty.
In "Server" event save the SESSION variables in a result variable.
$result["locationID"] = $_SESSION["locationID"]; $result["ownerID"] = $_SESSION["ownerID"];In "Client after" you set the value to the form fields. I assume your form fields named locationID and ownerID. If not then change the names.
`var locid = Runner.getControl(pageid, "locationID");
locid.setValue(result["locationID"]);

var ownid = Runner.getControl(pageid, "ownerID");
ownid.setValue(result["ownerID"]);`Regards,
wedi

P
pmuckle authorDevClub member 4/12/2023

Thanks Wedi, that is perfect