Arc Forumnew | comments | leaders | submitlogin
2 points by t1m 6166 days ago | link | parent

<?php

  session_start();
  
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $_SESSION['said'] = $_POST['said'];
    echo '<a href="">click here</a>';
  } else {
    if (isset($_SESSION['said'])) {
      echo 'You said: ' . $_SESSION['said'];
      unset($_SESSION['said']);
    } else {
      echo '<form method="post">';
      echo '<input type="text" name="said">';
      echo '<input type="submit">';
      echo '</form>';
    }
  }
  
?>


2 points by namaste 6166 days ago | link

Here's the same thing translated into Ruby + custom Web Framework + Tenjin:

<?rb

  if @w.req.post?
    @w.session['said'] = @w.f('said')
    @w << '<a href="">click here</a>'
  else
    if @w.session['said']
      @w << "You said: #{@w.session['said']}"
      @w.session.unset 'said'
    else
      @w << '<form method="post">'
      @w << '<input type="text" name="said">'
      @w << '<input type="submit">'
      @w << '</form>'
    end
  end

?>

BTW, your example made me spot a bug and fix it and also add the "unset" method to the Session class. Cool enough. Thanks! :-)

-----