• Hello —

    I’m having a problem preserving variables as I move from the form submission page to my success page using cforms II (v 10.2) on WordPress 2.7.

    Here’s the deal. I have a form. When the form is submitted, i have a function — very simple — which adds the form variables included in the array $cformsdata to the session variable. I need to use the variables in the page the user is directed to after successful completion of the form. Here’s that function:

    function my_cforms_action($cformsdata) {
    	$_SESSION['mbcdata'] = $cformsdata;
    	@mail('[email protected]', 'cforms my_action test', print_r($_SESSION,1), 'From: [email protected]');
    	}

    I’m certain the function is being called — I receive the mail. And $cformsdata is the correct variable. But it’s not working. The value of $_SESSION which I receive in the email is *only* what I assign to it; other session variables that are being passed don’t show up. And, when I’m sent to my success page, the value of the $_SESSION array includes the other session variables that are being passed, but not these new ones including the value of $cformsdata that are being assigned.

    In other words, it’s almost like the variable $_SESSION in this function is local to this function and is not the global $_SESSION. And I’m certain sessions are not being wiped out by WordPress, because I have these other session variables hanging around. (They’re from a non-WP script on the same site.)

    The strange thing is, this worked for a bit, and I suppose I might have changed something, but I have no idea what I might have changed.

    I’ve read through the PHP documentation on session handling, but I haven’t been able to figure out the problem. In particular, I haven’t any idea why $_SESSION doesn’t seem to be getting assigned. Any thoughts?

    Thanks in advance.

    – geoff

Viewing 1 replies (of 1 total)
  • Thread Starter geoff2

    (@geoff2)

    OK, I always make progress after I post.

    Apparently, when the function is being called, the session hasn’t been started. So if I modify the function as so, the session data is saved:

    function my_cforms_action($cformsdata) {
            session_start();
    	$_SESSION['mbcdata'] = $cformsdata;
    	@mail('[email protected]', 'cforms my_action test', print_r($_SESSION,1), 'From: [email protected]');
    	}

    The next time I visit a page, my session variables are nicely preserved. However, now that leads to another problem. With the addition of “session_start()”, the php script which processeses the data basically hangs and doesn’t redirect to the alternative success page that I set in the cforms preferences. I’m trying to puzzle it out, but no luck so far.

Viewing 1 replies (of 1 total)
  • The topic ‘cforms II, $_SESSION, and passing variables to new pages’ is closed to new replies.