1

Temat: [PHP] form

$text1 = "";
  $text2 = "";
  if ($_POST)
  {
    if (isset($_POST['text1'])) $text1 = $_POST['text1']; else $text1 = "";
    if (isset($_POST['text2'])) $text2 = $_POST['text2']; else $text2 = "";
    //
    echo "<h1>".$text1."</h1>";
    echo "<h2>".$text2."</h2>";
    echo "<h3>".((int)$text1+(int)$text2)."</h3>";
  }
?>
<form method="post">
  text1: <input type="text" name="text1" value="<?php echo $text1; ?>"><br>
  text2: <input type="text" name="text2" value="<?php echo $text2; ?>"><br>
  <input type="submit" name="" value="OK">
</form>

2

Odp: [PHP] form

<?php
  if ($_POST)
  {
    if (isset($_POST['text1'])) $text1 = $_POST['text1']; else $text1 = "";
    if (isset($_POST['text2'])) $text2 = $_POST['text2']; else $text2 = "";
    //
    if (isset($_POST['check1'])) $check1 = (int)$_POST['check1']; else $check1 = 0;
    //
    if (isset($_POST['radio1'])) $radio1 = (int)$_POST['radio1']; else $radio1 = 0;
  }
?>
<hr>
<form method="post">
  text1: <input type="text" name="text1" value=""><br>
  text2: <input type="text" name="text2" value=""><br>
  <input type="checkbox" name="check1" value="1"><br>
  <input type="radio" name="radio1" value="1"> r1<br>
  <input type="radio" name="radio1" value="2"> r2<br>
  <input type="radio" name="radio1" value="3"> r3<br>
  <input type="radio" name="radio1" value="4"> r4<br>
  <input type="submit" name="" value="OK">
</form>
<?php
  if ($check1) echo "true"; else echo "false";
  echo "<hr>";
  if ($radio1 == 0) echo "nie wybrano nic";
  if ($radio1 == 1) echo "r1";
  if ($radio1 == 2) echo "r2";
  if ($radio1 == 3) echo "r3";
  if ($radio1 == 4) echo "r4";
?>