【发布时间】:2015-10-12 19:55:05
【问题描述】:
我有一个带有两个提交按钮的页面,使用if ($_POST['action'] == 'Test SMS') 为我的“测试短信”按钮执行代码。我需要从 PHP 脚本执行代码,然后在不离开页面的同时给出一个警告框。
index.html
<form action="updateUserConfig.php" method="post">
<input type='submit' name='action' value='Test SMS' class='btn-test'>
<input type="submit" name="action" value="Save" class="btn btn-primary">
</form>
updateUserConfig.php
if ($_POST['action'] == 'Test SMS') { //action for Test SMS Button
//grab ntid and phone from header
if(isset($_POST['ntid'])) $ntid = $_POST['ntid'];
if(isset($_POST['phone'])) $phone = $_POST['phone'];
//using the notify_sms_users funtion from send_notification.php
require 'send_notification.php';
notify_sms_users(array($ntid), "", 4);
//alert user that there message has been sent
$alert = "Your message has been sent to " . $phone;
echo '<script type="text/javascript">alert("'.$alert.'");';
echo '</script>';
header('Location: index.php');
} else {-----action for other submit button------}
我在Alert after executing php script while not leaving current page 提出了一个类似的问题,该问题在Alert after executing php script while not leaving current page 被标记为重复,但我想出了一个解决方案,所以我想分享一下。
【问题讨论】:
-
-2 没有 cmets 或输入对于 Stack 的新手来说似乎有点苛刻。我确实已经对此进行了研究,我给出了我的代码的清晰示例,但我不知道为什么我会得到如此负面的回应。
-
只是猜测,但否决票可能是因为您几乎两次发布了相同的问题。我知道另一个被标记为重复,但我不明白为什么你得到了反对票。此外,关于确切问题的信息不足。什么有效,什么无效。你得到什么错误。等等等等
-
是的,社区对小事可能很苛刻。我有时也结束了。所以有一个 +1 这样你就不会推迟这个惊人的网络
标签: javascript php forms alert submit-button