index.php:
<code><span><span><?php</span><span>if</span> (<span>isset</span>(<span>$_POST</span>[<span>'userValue'</span>])&&!<span>empty</span>(<span>$_POST</span>[<span>'userValue'</span>])) { <span>echo</span><span>"您输入的是"</span>.<span>$_POST</span>[<span>'userValue'</span>]; } <span>else</span> { <span>echo</span><span>"没有接收到post值"</span>; } <span>?></span></span><span><!DOCTYPE html></span><span><<span>html</span><span>lang</span>=<span>"zh-CN"</span>></span><span><<span>head</span>></span><span><<span>meta</span><span>charset</span>=<span>"utf-8"</span>></span><span><<span>meta</span><span>http-equiv</span>=<span>"X-UA-Compatible"</span><span>content</span>=<span>"IE=edge"</span>></span><span><<span>meta</span><span>name</span>=<span>"viewport"</span><span>content</span>=<span>"width=device-width, initial-scale=1"</span>></span><span><!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --></span><span><<span>title</span>></span>music<span></<span>title</span>></span><span><!-- Bootstrap --></span><span><!-- 新 Bootstrap 核心 CSS 文件 --></span><span><<span>link</span><span>rel</span>=<span>"stylesheet"</span><span>href</span>=<span>"//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css"</span>></span><span></<span>head</span>></span><span><<span>body</span>></span><span><<span>div</span><span>class</span>=<span>"container"</span>></span><span><<span>form</span><span>action</span>=<span>"<?php echo $_SERVER['PHP_SELF']; ?>"</span><span>method</span>=<span>"post"</span>><span><<span>div</span><span>class</span>=<span>"input-group input-group-lg"</span>></span><span><<span>input</span><span>type</span>=<span>"text"</span><span>class</span>=<span>"form-control"</span><span>name</span>=<span>"userValue"</span><span>placeholder</span>=<span>"传到本页面"</span>></span><span><<span>span</span><span>class</span>=<span>"input-group-btn"</span>></span><span><<span>input</span><span>type</span>=<span>"submit"</span><span>class</span>=<span>"btn btn-default"</span><span>value</span>=<span>"GO!"</span>></span><span></<span>span</span>></span><span></<span>div</span>></span><span><!-- /input-group --></span><span></<span>form</span>></span><span><<span>form</span><span>action</span>=<span>"demo.php"</span><span>method</span>=<span>"post"</span>></span><span><<span>div</span><span>class</span>=<span>"input-group input-group-lg"</span>></span><span><<span>input</span><span>type</span>=<span>"text"</span><span>class</span>=<span>"form-control"</span><span>name</span>=<span>"userValue"</span><span>placeholder</span>=<span>"传到另一个页面"</span>></span><span><<span>span</span><span>class</span>=<span>"input-group-btn"</span>></span><span><<span>input</span><span>type</span>=<span>"submit"</span><span>class</span>=<span>"btn btn-default"</span><span>value</span>=<span>"GO!"</span>></span><span></<span>span</span>></span><span></<span>div</span>></span><span><!-- /input-group --></span><span></<span>form</span>></span><span></<span>div</span>></span><span><!-- jQuery文件。务必在bootstrap.min.js 之前引入 --></span><span><<span>script</span><span>src</span>=<span>"//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"</span>></span><span></span><span></<span>script</span>></span><span><!-- 最新的 Bootstrap 核心 JavaScript 文件 --></span><span><<span>script</span><span>src</span>=<span>"//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"</span>></span><span></span><span></<span>script</span>></span><span></<span>body</span>></span><span></<span>html</span>></span></code>
demo.php:
<code><span><span><?php</span><span>if</span> (<span>isset</span>(<span>$_POST</span>[<span>'userValue'</span>])&&!<span>empty</span>(<span>$_POST</span>[<span>'userValue'</span>])) { <span>echo</span><span>"您输入的是"</span>.<span>$_POST</span>[<span>'userValue'</span>]; } <span>else</span> { <span>echo</span><span>"没有接收到post值"</span>; } <span>?></span></span><span><<span>meta</span><span>charset</span>=<span>"utf-8"</span>></span></code>
저작권: 이 글은 블로거의 원본 글입니다. 작성자의 승인을 받지 않았으며 블로거의 허가를 받아 재인쇄하는 것은 허용되지 않습니다.
이상으로 관련 내용을 포함하여 PHP 폼 케이스를 소개하였습니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되었으면 좋겠습니다.