Jump to content

PW 3.0.8: How to save $input into $session?


titanium
 Share

Recommended Posts

(I already posted this in ProcessWire's issue list at github a week ago, but I'm not too sure if this really is an issue I should Ryan bother with. I hope it can be better answered/discussed by the community).

I would like to collect form data in a session and do a redirect afterwards. After the redirect happens, I would like to read the form data back from the session. This follows the concept of the PRG-Pattern, which I consider as a good practice to avoid duplicate form submissions.

In 2.7.2, the following code worked flawlessly. In 3.0.8, I can't get it to work anymore.

Here's my simple test case (save it as "test.php", in parallel to the index.php). I hope somebody can give me a hint what's wrong with it.

<?php

include './index.php';

if ($input->post->submit) {
    $session->input = $input;
    $session->redirect('./test.php');
}

if ($session->input && $session->input->post) {
    // 2.7.2: echoes "1"
    // 3.0.7: echoes nothing!
    foreach ($session->input->post as $value) {
        echo $value;
    }
    $session->remove('input');
}

?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<form action="" method="post">
    <button type="submit" name="submit" value="1">send</button>
</form>

</body>
</html>
Link to comment
Share on other sites

Just tested your code under PW 2.7 and 3, I can't get it working on both version with the line $session->redirect(basename(__FILE__));

Commenting the line, it show the integer (value 1) on both version.

Thanks for testing!

If you comment the line, than value 1 is shown. The difference is only visible after the redirect. May I ask you to try again with:

$session->redirect('./test.php');

given the file is named "test.php". I did edit my version above.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...