Arc Forum | Perhaps a more traditional PHP version is: <?php // unvarying HTML el...

8 points by randallsquared 6500 days ago | link | parent

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 6494 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 6377 days ago | link

thank you for reaffirming my faith in php.

-----




AltStyle によって変換されたページ (->オリジナル) /