[英]Input type=button as if it were type=submit
我需要有兩個不同類型的輸入:
<input type="button" **onclick = "?????"** name="back" value="← Back" >
<input type="submit" name="submit" value="Forward →" >
我該如何為 type=button 運行此 PHP 代碼:
<?php
if (isset($_POST['back']))
{
$_SESSION['onpage'] = $_SESSION['onpage'] - 1;
$query_questionset = "
select Q.Constructor AS Constructor,
QS.QuestionIDFKPK AS QuestionIDFKPK,
Q.QuestionValue AS QuestionValue,
QS.SortOrder AS SortOrder,
QS.onpage AS onpage
from tbluserset AS US
inner join tblquestionset AS QS ON US.QuestionSetIDFKPK = QS.QuestionSetIDPK
inner join tblquestion AS Q ON QS.QuestionIDFKPK = Q.QuestionIDPK
where (US.UserIDFKPK = " . $UserId . ")
and (US.UserSetIDPK= '" . $_SESSION['UserSetIDPK'] . "')
and (QS.onpage = '" . $_SESSION['onpage'] . "')
order by QS.SortOrder";
}
$QuestionSet_Constructors = mysql_query($query_questionset);
?>
我的表單和輸入提交完美地工作:
<form id= "formID" class="formular" method="post" action= "<?= $url = "QUESTIONAREnewdatabase.php"; ?>" accept-charset="utf-8">
我需要input type=button
來運行 PHP 代碼和操作表單,就像 Back 有type=submit
?
試試這個
< input type="submit" onclick = "?????" name="back" value="← Back" >
<form action="" id="formID" class="formular" method="post" accept-charset="utf-8">
<!-- Your inputs here -->
<button type="submit" name="back">← Back</button>
<button type="submit" name="submit">Forward →</button>
</form>
下面是一個使用JavaScript,這將動態創建和附加一個隱藏的輸入稱為一種方式back
的形式,然后提交表單-單擊后退按鈕時。
<script>
function postBack()
{
var myForm = document.getElementById("formID");
var backInput = document.createElement("input");
backInput.type = "hidden";
backInput.name = "back";
backInput.value = "1";
myForm.appendChild(backInput);
myForm.submit();
}
</script>
<input type="button" onclick="postBack()" name="back" value="← Back">
在服務器端,您現在可以測試:
if(isset($_POST['back']))
{
// back was pressed...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.