Having built my entire booking form’s server actions based on storing values retrieved from the database in PHP Session variables, I have just found that those variables are shared between browser tabs.
I need my users to be able to have multiple booking forms open in different tabs of the same browser, and for each to work with their own unique data.
Is there any way around this, or do I just need to re-write 1000s of lines of server action steps in a way that doesn’t use PHP Sessions Variables?
Solutions that I google talk about using a PHP Session array, but I don’t have access to that concept from a Server Action!
Ouch. I don’t think you’re going to get around the fact that user sessions are per browser user, not per tab. In other words, in typical usage, each tab for a single browser is considered the same user. If you have setup different users for your browser, then they are in fact different users and thus different php sessions, but that is usually a big ask of users – doesn’t sound like a option here.
I believe session and local storage within the browser, however, IS per tab, so that might be part of your solution, albeit still some kind of overall change in methodology.
I feel your pain Antony. Hang in there, you’ll get it.
This seems to be a big thing that is completely not obvious for those of us who come to Wappler without a PHP background.
I have soooo much data going on, some of which I need to keep hidden from the user, that I think I’ll just pass the minimum to the browser and introduce more database queries and temporary stores in the database to make it all work. Otherwise my GET and POST lists are going to be even longer than they are now.
I’m just now getting started with Wappler (literally bought the pro license this morning) so I’m unfamiliar with all it can do or any limitations and I also don’t know the workings of your form, but if the user has to click a link to open a new tab, could you have a url variable on the link test whether a session variable exists on tab load and if so, increment a number. Then when the user clicks the link to open a new tab/window the page adds that number to the session variable name thus making it unique? For instance if one of the variables of the form is my_var the next instance would be my_var1. After the first pass you check to see if the increment variable already has a value and keep incrementing. So the next instance is my_var2 and so on. The number would be appended to each variable for that tab and your action code would make sure the end numbers match and are grouped together. Basically push them to an array. Assuming you can’t make the form input names an array. Again, I don’t know your code but just thinking off the top of my head.
How about using the technique Google uses with gmail? If you have multiple accounts, the url has a number added to distinguish which user it is, eg. /user/0, the next tab is /user/1. You can then use that value to add to the session names. I think that’s how it would work, anyway. Any help?
Similar ideas were buzzing in my head for 5 minutes until I looked through my server actions, and realised they would be too much hassle to implement, especially as quite a lot of my values are numeric.
I’ll add in the extra database searches and do it that way I think…
Whatever you do will require work on all your server actions but I’m trying to find a way to keep that to a minimum and also keep it all nice and tidy.
Not sure how your variables are named but could you loop through them using PHP and use a str_replace(‘my_var’,‘my_var’.$increment,$my_var) or regex? Or is the problem there is not one or two places to run the code because you have a lot of actions? Sorry if I’m way off on my suggestions since I don’t know how your actions are structured. I’m also doing 10 different things while I try and think of what I would do haha.
Looks like a lot of rework is on the way.
From the sounds of it, I don't quite get why you were using session variables in the first place.
If they are being set from client side values, you should have just inserted them into the table.
I don't know what yoir exact workflow is, but using server session continuously for client side data looks wrong.
It would be wise to take a look at the architecture and flow before starting rework.
As for POST and GET variables in SA, the count of that does not really matter. You can make use of linked forms to have it created from the page itself and they are just UI/validation helpers.. If you don't define them, you can still use them in steps.
Can you not use a repeat for the forms (if they are all the same), on a single page to accomplish this? Why the need for multiple tabs if you don’t mind me asking Antony?
Not exactly booking forms but works really well (following video). Each click is stored to an array, in turn the array has a show/hide. If in the array show the icon. The selection is passed to a multi update (could be insert just as easily). May give you some ideas?
Thanks for all your positive ideas and feedback… I really appreciate it!
My booking form requires a large amount of data fields to be read from the database about the activity that is being booked, and that information is used across about 10 very large server actions… so I was reading the data once and then storing it in PHP session variables to save having to keep hitting the database each time a new server action was read. The user input is all manage in browser session data, and this isn’t an issue as it is held separately for each tab.
Since the booking form will be used by my user’s clients then I have no control over how they will choose to use it, and it is quite possible they will open forms to book multiple events in different browser tabs so I need to be able to manage that.
I will work my way through each server action and add more database reads to bring in the data for each sever action to get around the issue I have.
I’ll also put in a Feature Request to see if in the future Wappler can store the PHP session values in an array structure that makes them tab independent.
If it accepts a string we could do this ourselves. Using JSON we can Stringify the JSON and store it in the session variable and then use JSON.parse when we pull it. This would allow us to have dynamic storage within a single variable.