[英]PHP version of confirm() of JavaScript
是否有PHP版本的confirm()函數?
如果沒有,我的其他選擇是什么,或者我如何制作類似於confirm()的內容?
因為PHP是服務器端語言(所有PHP代碼都在服務器上執行,代碼的輸出發送到客戶端),所以你必須使用提交或取消按鈕制作一個HTML表單。你的PHP頁面。 像這樣的東西:
confirm.php:
<p>Are you sure you want to do this?</p>
<form action="page2.php" method="post">
<input type="submit" name="ok" value="OK" />
<input type="submit" name="cancel" value="Cancel" />
</form>
使page2.php:
<?php
if (isset($_POST['ok'])) {
// They pressed OK
}
if (isset($_POST['cancel'])) {
// They pressed Cancel
}
?>
使用上一篇文章中的相同答案添加一些錯誤處理和安全性:
<form action="page2.php" method="post">
Your choice: <input type="radio" name="choice" value="yes"> Yes <input type="radio" name="choice" value="no" /> No
<button type="submit">Send</button>
</form>
在你的page2.php中:
if (isset($_POST['choice']) /* Always check buddy */) {
switch($_POST['choice']) {
case 'yes':
/// Code here
break;
case 'no':
/// Code here
break;
default:
/// Error treatment
break;
}
}
else {
// error treatment
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.