Kurrel Posted September 13, 2007 Share Posted September 13, 2007 Hey everyone, I have a system wherein different scores can be entered by month. The details for the selected month are displayed, and with a calendar box or by left and right arrows the user can move the form to different months. I've done this via resubmitting on-clicks that load $_POST with the desired month and year. When details are entered and the 'Save' button is pressed, javascript changes the form action to another PHP function and then submits the page. In this function, CommitScores function commitScores() { if($_POST["conf"]) { $conf = $_POST["conf"]; } $data["month"] = $conf["month"]; $data["year"] = $conf["year"]; $data["deptid"] = $conf["deptid"]; if($conf["deptid"] > 0) { foreach ($conf["scores"][$conf["deptid"]] as $scorekey=>$scoreval) { $data["catid"] = $scorekey; $data["score"] = $scoreval; clearScore($data); createScore($data); } } print("<form id=postform action='index.php?mode=test/index&action=scoresys' method=post>"); print("<input name=conf[month] value=".$conf["month"].">"); print("<input name=conf[year] value=".$conf["year"].">"); print("<input name=conf[deptid] value=".$conf["deptid"].">"); print("<pre style='font-family:verdana;font-size:13'>"); print_r($conf); print("</pre>"); print("</form>"); // JavaScript { print("<script> document.getElementById('postform').submit(); </script>"); // } } It removes the old score and enters the new one... and is then meant to return the scoresys function and display that month and year with the the new scores. I can just redirect to that function, but it returns to the default month and year (Last month, this year) whereas I need it to be the recently edited one. This way works, but only if I print something to the screen (in this case, the <pre>$conf set). I suspect this is because of headers, but stand to be corrected. If I don't print something, the $_POST is not loaded, not does the form submit, leaving the user on a blank page after the DB stuff is done. It's not slick to have to print text in a back-end function between submissions and I'm hoping there's another way to load $_POST and return it to the original function. Quote Link to comment https://forums.phpfreaks.com/topic/69175-solved-returning-variables-to-a-calling-function/ Share on other sites More sharing options...
phat_hip_prog Posted September 13, 2007 Share Posted September 13, 2007 Not fully understanding this, but either use hidden form elements or use session variables: $_SESSION['myvar'] = xyz; Quote Link to comment https://forums.phpfreaks.com/topic/69175-solved-returning-variables-to-a-calling-function/#findComment-347666 Share on other sites More sharing options...
Kurrel Posted September 13, 2007 Author Share Posted September 13, 2007 Using $_SESSION works, bit of an akward workaround though. I am still wondering why the form and hidden variables only exist after some text has been printed by the function. If I don't print anything, the form doesn't submit and the data isn't prepped. Quote Link to comment https://forums.phpfreaks.com/topic/69175-solved-returning-variables-to-a-calling-function/#findComment-347682 Share on other sites More sharing options...
heckenschutze Posted September 13, 2007 Share Posted September 13, 2007 BTW, < pre > works and is designed to use fixed-width fonts. Verdana is NOT fixed width, Courier New is. Quote Link to comment https://forums.phpfreaks.com/topic/69175-solved-returning-variables-to-a-calling-function/#findComment-347684 Share on other sites More sharing options...
Kurrel Posted September 13, 2007 Author Share Posted September 13, 2007 Thank you. I'm going to set the topic as solved because, despite remaining curious, the original problem is finished. Quote Link to comment https://forums.phpfreaks.com/topic/69175-solved-returning-variables-to-a-calling-function/#findComment-347699 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.