I have a form action that takes all of its values puts them in an array and stores this in a session. I have a update button so if they change any info and then click update it should reflect those changes. This all works fine if every time the array stays keeps the same keys and just the values change. When the form updates, some fields may be removed so If I try to Session::set to overwrite whats currently there with a new array with less elements, it will change the values that are there but will keep the old elements that no longer exist.
So it seems like its merging and not overwriting when I call Session::set with the new array. I have tried clearing the session right before I call set again and this doesn't work either.
So something like this:
function myFormUpdateAction($data,$form){
$newArr = array();
foreach($data as $key=>$value){
$arr = array($key=>$value);
$newArr=array_merge($newArr,$arr);
}
Session::set('MySession',$newArr);
Director::redirect('/my-page/'); //goes back to same page and builds the form again with the values from the session
}