Arc Forumnew | comments | leaders | submitlogin
4 points by randallsquared 5923 days ago | link | parent

The way I do PHP, there'd be two templates, a.html and c.html (for example), and a separate page b.html. Then, a.php would have

    <?php
    require_once('liball.php');
    
    if ($foo = $_POST['foo']) {
      $_SESSION['foo'] = $foo;
      localredirect('b.html');
    }
    sendpage('a');
    ?>
The template a.html has the form, and b.html just has the link on it.

Assuming page c needs to be protected against people just coming to it:

    <?php
    require_once('liball.php');
    if (!($foo = $_SESSION['foo'])) {
      localredirect('a.php');
    }
    sset('foo', $foo);
      
    
    sendpage('c');
    ?>
and the c.html template has in it

    you said: {$foo}
The only parts of this that aren't standard in PHP are the sset() and sendpage() calls, which are short for some longer stuff involving a template object, and the localredirect(), which just does some bookkeeping.

This is a lot longer than the Arc example, of course. However, one advantage it has (which is a must for some of us) is that once I'm done writing it, I can hand the html files to a web designer and I don't have to do anything at all when the boss/client wants to completely change the way it looks.



8 points by randallsquared 5923 days ago | link

Perhaps a more traditional PHP version is:

    <?php
    // unvarying HTML elided above
    if ($foo = $_POST['foo']) {
      $_SESSION['foo'] = $foo;
      print '<a href="">click here</a>';
    } else if ($foo = $_SESSION['foo']) {
      print 'you said: ' . $foo;
    } else {
      print "<form method='post'><input type='text' name='foo'><input type='submit'></form>";
    }
    ?>

-----

1 point by bonzinip 5916 days ago | link

More complicated, but scales better to more complex problems and it is back-button friendly.

    <?php
      $step = isset ($_POST['step']) ? $_POST['step'] : 0;
      if ($step == 0)
        $_POST = array();

      $_POST['step'] = ($step + 1) % 3;
      echo '<form method="post">';
      foreach ($_POST as $k => $v)
        echo '<input type="hidden" name="' . htmlspecialchars ($k) . '"
            value="' . htmlspecialchars (stripslashes ($v)) . '" />';
    
      echo '<p>';
      switch ($step)
        {
        case 0:
          echo '<input type="text" name="simon-sez">';
          break;
        case 1:
          echo 'Simon sez...';
          break;
        case 2:
          echo htmlspecialchars (stripslashes ($_POST['simon-sez']));
          break;
        }
      echo '</p>';
      echo '<input type="submit" value="Go on" />';
      echo '</form>';
    ?>

-----

1 point by rekall 5799 days ago | link

thank you for reaffirming my faith in php.

-----