Using sessionStorage to snapshot $_SESSION value (v2018)

Tips submitted by PHPMaker users
Post Reply
sangnandar
User
Posts: 980

Using sessionStorage to snapshot $_SESSION value (v2018)

Post by sangnandar »

Codes below are to solve viewtopic.php?f=4&t=49189

BACKGROUND
- App is v2018
- App is using ew_IsMobile() switch, if (mobile) then use-href else (PC) use-modal

SETUP
Schema:
`id` auto-increment,
`date` date
etc
PHPM:
EditTag -> `date` is hidden <input type="hidden" id="x_date" value>

CODES
"tablelist.php"
Page_Load
ew_SetClientVar("IsMobile", ew_IsMobile());
Page_Render
ew_SetClientVar("date", $this->date->AdvancedSearch->SearchValue);
Client
$(function(){
$('a').click(function(){
if (ewVar.IsMobile) {
// copy into localStorage
localStorage.setItem('date', ewVar.date);
} else {
// use-modal, no need to set localStorage
}
});
});

"tableadd.php"
$(function(){
if (ewVar.IsMobile) {
// cut-paste localStorage into sessionStorage
sessionStorage.setItem('date', localStorage.getItem('date'));
localStorage.removeItem('date');
// set <input type="hidden" value>
$('#x_date').attr("value", sessionStorage.getItem('date'));
} else {
// use-modal, no need localStorage
$('#x_date').attr("value", sessionStorage.getItem('date'));
}
});

EXPLANATION
The basic idea is to copy then cut-paste value between sessionStorage and localStorage (google:"difference between sessionStorage and localStorage").
- List Page writes $_SESSION search-value into ewVar.date
- ewVar.date then copied into Add Page via localStorage
- any future-change of $_SESSION search-value of List Page WOULD NOT affect sessionStorage of Add Page

sangnandar
User
Posts: 980

Post by sangnandar »

The more proper solution would be to use Broadcast_Channel_API.
The problem is: Safari don't support that yet.

sangnandar
User
Posts: 980

Post by sangnandar »

CORRECTION
For modal-add the code should be wrapped inside
$("#ewModalDialog").on('shown.bs.modal', function(){
// code
} );

Post Reply