ramone_johnny Posted May 6, 2013 Share Posted May 6, 2013 (edited) Im passing form values over to a confirmation page where Im setting session variables in order to allow the user to "go back" if they wish, to ammend their previous entries. I just wanted to ask....this seems very cumbersome. Is there a smarter way to do this? Because I have about 50 values from the form. $_SESSION['share_header'] = isset($_REQUEST["share_header"]) ? $_REQUEST["share_header"] : ""; $_SESSION['share_rent'] = isset($_REQUEST["share_rent"]) ? $_REQUEST["share_rent"] : ""; $_SESSION['share_bond'] = isset($_REQUEST["share_bond"]) ? $_REQUEST["share_bond"] : ""; $_SESSION['share_proptype'] = isset($_REQUEST["share_proptype"]) ? $_REQUEST["share_proptype"] : ""; $_SESSION['theDate'] = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : ""; $_SESSION['share_num'] = isset($_REQUEST["share_num"]) ? $_REQUEST["share_num"] : ""; $_SESSION['share_street'] = isset($_REQUEST["share_street"]) ? $_REQUEST["share_street"] : ""; $_SESSION['share_location'] = isset($_REQUEST["search"]) ? $_REQUEST["search"] : ""; $_SESSION['share_description'] = isset($_REQUEST["share_description"]) ? $_REQUEST["share_description"] : ""; Edited May 6, 2013 by ramone_johnny Quote Link to comment https://forums.phpfreaks.com/topic/277714-session-variables-is-there-a-smarter-way-to-do-this/ Share on other sites More sharing options...
litebearer Posted May 6, 2013 Share Posted May 6, 2013 Consider ... session variables can contain arrays; $_POST is an array Quote Link to comment https://forums.phpfreaks.com/topic/277714-session-variables-is-there-a-smarter-way-to-do-this/#findComment-1428649 Share on other sites More sharing options...
ramone_johnny Posted May 6, 2013 Author Share Posted May 6, 2013 Yes, I have a selection of checkboxes that contain an array. The rest are just regular entries (text areas, drop downs etc) It just felt "clunky" writing all of the session variables out like that. Quote Link to comment https://forums.phpfreaks.com/topic/277714-session-variables-is-there-a-smarter-way-to-do-this/#findComment-1428650 Share on other sites More sharing options...
Zane Posted May 6, 2013 Share Posted May 6, 2013 Just save your entire POST array to your session unless you have certain field that you DO NOT want to save. $_SESSION['submittedForm'] = $_POST; Quote Link to comment https://forums.phpfreaks.com/topic/277714-session-variables-is-there-a-smarter-way-to-do-this/#findComment-1428662 Share on other sites More sharing options...
ramone_johnny Posted May 8, 2013 Author Share Posted May 8, 2013 Thanks Zane. There are, unfortunately quite a few variables being passed that I don't need. I think I might have to stick to the way I'm doing it. Looks a bit clunky, but works. Cheers mate. Quote Link to comment https://forums.phpfreaks.com/topic/277714-session-variables-is-there-a-smarter-way-to-do-this/#findComment-1429023 Share on other sites More sharing options...
Zane Posted May 9, 2013 Share Posted May 9, 2013 Then don't store those fields in the session, simple as that. $_POST is an array. Using countless techniques, you can filter out what you do not want. The best strategy? Blacklists and Whitelists. If you have more fields that you need to save than you do the fields you don't want to save, then create a blacklist for those you want to avoid storing If you have more fields that you do not need to save than you do fields you want to save, then create a whitelist for those you do indeed want to store. I'm not exactly sure how you're data look, so I can't exactly write out a blacklist/whitelist ad-hoc script for you. Programming is a logic game, play it. Quote Link to comment https://forums.phpfreaks.com/topic/277714-session-variables-is-there-a-smarter-way-to-do-this/#findComment-1429223 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.