Home > php教程 > php手册 > PHP提交表单

PHP提交表单

WBOY
Release: 2016-06-06 16:04:03
Original
1345 people have browsed it

二种提交方式,提交到其它页面和提交到本身见代码:

<!DOCTYPE html>
<html>
<title>表单提交开始</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body>
     返回首页
     <hr></hr>
<b>一、表单提交到另一个php上</b><br />
<form action="formTo.php" method="POST">
    Name:  <input type="text" name="username"><br />
    Email: <input type="text" name="email"><br />
    <input type="submit" name="submit" value="提交" />
</form>
<hr/>
<b>二、将一个表单 POST 给自己并在提交时显示数据:</b><br />
<br/>
<?php
if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
    echo '<pre class="brush:php;toolbar:false">';

    print_r($_POST);
    echo '返回重填';

    echo '
Copy after login
'; } else { ?>
Name:
Email:
Beer:

 formTo.php

<!DOCTYPE html>
<html>
<title>表单提交</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body>
     返回首页
     <hr></hr>
<?php
    // 自 PHP 4.1.0 起可用
   echo "<br/>  _POST"; echo $_POST['username'];
   echo "<br/>  _REQUEST";echo $_REQUEST['email'];
   
   import_request_variables('p', 'p_');
   echo "<br/>  p_username";echo $p_username;
    // PHP 6以后将无效。自 PHP 5.0.0 起,这些较长的预定义变量
    // 可用 register_long_arrays 指令关闭。
   echo "<br/>  HTTP_POST_VARS"; echo $HTTP_POST_VARS['username'];

?>
</body>
</html>
Copy after login

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template