Maison  >  Article  >  php教程  >  PHP 对 GET 和 POST 的表单提交方式处理

PHP 对 GET 和 POST 的表单提交方式处理

PHP中文网
PHP中文网original
2016-05-25 17:16:02988parcourir

<html>
</head>
<body>
    <?php
      if ($_GET[&#39;submitted&#39;] == "yes"){
        if (trim ($_GET[&#39;yourname&#39;]) != ""){
          echo "Your Name (with GET): " . $_GET[&#39;yourname&#39;];
        } else {
          echo "You must submit a value.";
        }
        ?><br /><a href="index.php">Try Again</a><?php
      }
      if ($_POST[&#39;submitted&#39;] == "yes"){
        if (trim ($_POST[&#39;yourname&#39;]) != ""){
          echo "Your Name (with POST): " . $_POST[&#39;yourname&#39;];
        } else {
          echo "You must submit a value.";
        }
        ?><br /><a href="index.php">Try Again</a><?php
      }
    ?>
    <?php
      if ($_GET[&#39;submitted&#39;] != "yes" && $_POST[&#39;submitted&#39;] != "yes"){
        ?>
        <form action="index.php" method="get">
          <p>GET Example:</p>
          <input type="hidden" name="submitted" value="yes" />
          Your Name: <input type="text" name="yourname" maxlength="150" /><br />
          <input type="submit" value="Submit with GET"/>
        </form>
        <form action="index.php" method="post">
          <p>POST Example:</p>
          <input type="hidden" name="submitted" value="yes" />
          Your Name: <input type="text" name="yourname" maxlength="150" /><br />
          <input type="submit" value="Submit with POST"/>
        </form>
        <?php
      }
    ?>
</body>
</html>


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn