Jump to content

[SOLVED] Returning variables to a calling function


Kurrel

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.