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)文章
關(guān)于PHP結(jié)束標(biāo)簽的使用細(xì)節(jié)探討及聯(lián)想
PHP解析文件時(shí)會(huì)尋找開始?php和結(jié)束標(biāo)記?,標(biāo)記告訴PHP開始和停止解釋其中的代碼,接下來將詳細(xì)介紹下PHP結(jié)束標(biāo)簽的使用細(xì)節(jié)感興趣的你可以參考下本文或許可以幫助到你2013-03-03
php使用pclzip類實(shí)現(xiàn)文件壓縮的方法(附pclzip類下載地址)
這篇文章主要介紹了php使用pclzip類實(shí)現(xiàn)文件壓縮的方法,分析了使用pclzip類的具體步驟與實(shí)現(xiàn)文件壓縮的相關(guān)技巧,并附帶pclzip類文件的下載地址,需要的朋友可以參考下2016-04-04
PHP學(xué)習(xí)筆記(三):數(shù)據(jù)類型轉(zhuǎn)換與常量介紹
這篇文章主要介紹了PHP學(xué)習(xí)筆記(三):數(shù)據(jù)類型轉(zhuǎn)換與常量介紹,本文講解了PHP數(shù)據(jù)類型相互轉(zhuǎn)換、常量的聲明與使用等內(nèi)容,需要的朋友可以參考下2015-04-04
php讀取圖片內(nèi)容并輸出到瀏覽器的實(shí)現(xiàn)代碼
如果php以圖片,zip,exe等文件輸出到瀏覽器,而前面還輸出了其他字符,那就會(huì)是你看到的亂碼2013-08-08
PHP中date()日期函數(shù)有關(guān)參數(shù)整理
PHP中date()日期函數(shù)有關(guān)參數(shù)整理,需要的朋友可以參考下。2011-07-07

