php 多個(gè)submit提交表單 處理方法
更新時(shí)間:2009年07月07日 14:09:10 作者:
php中一個(gè)多個(gè)submit提交表單如何處理(區(qū)分不同的表單提交)
test.php
<?php
$test = $_POST[ 'test '];
echo '12 ';
echo $test;
echo $_POST[ 'submit1 '];
echo $_POST[ 'submit2 '];
if (isset($_POST[ 'submit1 ']) && $_POST[ 'submit1 '] == 'submit1 ')
{
echo 'ok1 ';
}
if (isset($_POST[ 'submit2 ']) && $_POST[ 'submit2 '] == 'submit2 ')
{
// echo " <meta http-equiv=refresh content= '0; url=http://localhost:8000/php/index.php '> ";
// header( "Location:index.php ");
// break;
echo 'ok2 ';
}
?>
<html>
<head> </head>
<body>
<form action= 'xajaxtest.php ' method= 'POST '>
<input type= 'hidden ' name= 'test ' value= 'test1 '>
<input name= 'submit1 ' type= 'submit ' value= 'submit1 ' title= 'submit1 '>
<input name= 'submit2 ' type= 'submit ' value= 'submit2 ' title= 'submit2 '>
</form>
</body>
</html>
為什么 這個(gè)測試頁面 載入后第一次不傳數(shù)據(jù)?
echo $_POST[ 'submit1 '];echo $_POST[ 'submit2 '];都打印空
之后就好了。這個(gè)是什么原因 有沒有辦法解決?
方法二:
<script language= "JavaScript "><!--
function check(){
frm.action = "checkname.php "
}
function mysubmit() {
frm.action = "zhuce.php "
}
// --></script>
<form method=post action= " " name= "frm ">
<input type= "submit " onclick= "check() ">
<input type= "submit " onclick= "mysubmit() ">
</form>
復(fù)制代碼 代碼如下:
<?php
$test = $_POST[ 'test '];
echo '12 ';
echo $test;
echo $_POST[ 'submit1 '];
echo $_POST[ 'submit2 '];
if (isset($_POST[ 'submit1 ']) && $_POST[ 'submit1 '] == 'submit1 ')
{
echo 'ok1 ';
}
if (isset($_POST[ 'submit2 ']) && $_POST[ 'submit2 '] == 'submit2 ')
{
// echo " <meta http-equiv=refresh content= '0; url=http://localhost:8000/php/index.php '> ";
// header( "Location:index.php ");
// break;
echo 'ok2 ';
}
?>
復(fù)制代碼 代碼如下:
<html>
<head> </head>
<body>
<form action= 'xajaxtest.php ' method= 'POST '>
<input type= 'hidden ' name= 'test ' value= 'test1 '>
<input name= 'submit1 ' type= 'submit ' value= 'submit1 ' title= 'submit1 '>
<input name= 'submit2 ' type= 'submit ' value= 'submit2 ' title= 'submit2 '>
</form>
</body>
</html>
為什么 這個(gè)測試頁面 載入后第一次不傳數(shù)據(jù)?
echo $_POST[ 'submit1 '];echo $_POST[ 'submit2 '];都打印空
之后就好了。這個(gè)是什么原因 有沒有辦法解決?
方法二:
<script language= "JavaScript "><!--
function check(){
frm.action = "checkname.php "
}
function mysubmit() {
frm.action = "zhuce.php "
}
// --></script>
<form method=post action= " " name= "frm ">
<input type= "submit " onclick= "check() ">
<input type= "submit " onclick= "mysubmit() ">
</form>
相關(guān)文章
SQL server不支持utf8 php卻用utf8的矛盾問題解決方法
這篇文章主要介紹了SQL server不支持utf8 php卻用utf8的矛盾問題解決方法,需要的朋友可以參考下2020-03-03Ubuntu12下編譯安裝PHP5.3開發(fā)環(huán)境
本文給大家分享的是在Ubuntu12下編譯安裝PHP5.3開發(fā)環(huán)境的方法和步驟,十分的細(xì)致,推薦給大家,有需要的小伙伴們可以參考下。2015-03-03php模塊memcache和memcached區(qū)別分析
談及php搭配memcached使用,已經(jīng)是老生常談的問題。但是有一些細(xì)節(jié),不見得人人清楚。比如說php的模塊memcache和memcached有什么區(qū)別等。下面我就簡單介紹一下。2011-06-06PHP提示Notice: Undefined variable的解決辦法
今天在調(diào)試程序的時(shí)候,很多網(wǎng)上提供的源碼都會(huì)出現(xiàn) Undefined variable錯(cuò)誤,一般情況下php是不需要定義變量的,但如果服務(wù)器什么都報(bào)錯(cuò)的,就會(huì)出現(xiàn)錯(cuò)誤,所以服務(wù)器上都是應(yīng)該屏蔽這種錯(cuò)誤的2012-11-11