PHP 表单上的 jQuery 弹出对话框确认并刷新页面 - 不起作用

发布于 2024-12-13 02:58:51 字数 1488 浏览 0 评论 0原文

我已经看到了似乎有一百种方法可以做我想做的事,但我似乎无法让任何一种方法发挥作用。我这里有一个测试页面: http://upcycledonline.com/test/Site/defaultUpCyc.php

我想要发生的是,当用户单击“提交”时,会出现一个弹出窗口,显示“谢谢!您的电子邮件已添加”。当他们单击“确定”时,弹出窗口将关闭并刷新页面。现在我有弹出窗口,但单击“确定”按钮后,它会转到我的 PHP 页面。

仅供参考:我是 PHP 和 Javascript 新手

,这是表单代码和 Javascript

<div id="signUp"> 


<script>
function confirmSubmit() {
if (confirm("Are you sure you want to submit the form?")) {
document.getElementById("FORM_ID").submit();
}
return false;
}

</script>


<?php 
//if the validation falls back to php, then print the validation error
if (isset($error_message)) echo $error_message;
?>
<form method="post" action="process-form.php" id="emailForm" name="emailForm" target="_self">
        
    <h4>Sign up to be notified when we go live!</h4>
    <!--value="<?php if (isset($_POST['email'])) echo $_POST['email'];?>"-->
    
<label for="email">E-mail</label>
    <input type="text" name="email" id="email" />
    <!-- onSubmit="alert('Thank you. Your email has been added.')"-->
<input type="submit" name="submit" id="submit" value="Submit"  onclick="return           confirm('Are you sure?');">

    <p>emails will not be shared with third parties</p>
</form>
<script>
<?php echo $validation_js_code;?>
</script>
</div> 

I have seen what seems like a hundred ways to do what I want but I can't seem to get a single one to work. I have a test page here : http://upcycledonline.com/test/Site/defaultUpCyc.php

What I want to happen is when the user clicks submit a pop window appears saying "Thanks! Your email has been added". When they click 'ok' the pop will close and the page refreshes. Right now I have the pop up going but after clicking the ok button it goes to my PHP page.

FYI: I am new to PHP and Javascript

Here is the form code and Javascript

<div id="signUp"> 


<script>
function confirmSubmit() {
if (confirm("Are you sure you want to submit the form?")) {
document.getElementById("FORM_ID").submit();
}
return false;
}

</script>


<?php 
//if the validation falls back to php, then print the validation error
if (isset($error_message)) echo $error_message;
?>
<form method="post" action="process-form.php" id="emailForm" name="emailForm" target="_self">
        
    <h4>Sign up to be notified when we go live!</h4>
    <!--value="<?php if (isset($_POST['email'])) echo $_POST['email'];?>"-->
    
<label for="email">E-mail</label>
    <input type="text" name="email" id="email" />
    <!-- onSubmit="alert('Thank you. Your email has been added.')"-->
<input type="submit" name="submit" id="submit" value="Submit"  onclick="return           confirm('Are you sure?');">

    <p>emails will not be shared with third parties</p>
</form>
<script>
<?php echo $validation_js_code;?>
</script>
</div> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨扶苏 2024-12-20 02:58:51

您可以做几件事:

  1. 将表单处理逻辑移至defaultUpCyc.php,将表单提交到该URI,然后让defaultUpCyc.php 处理表单并重新加载页面。
  2. 使用 AJAX,并将数据发布到 process-form.php,这根本不需要任何刷新。
  3. 在 process-form.php 中重定向到 defaultUpCyc.php。

You could do a couple things:

  1. move your form processing logic to defaultUpCyc.php, submit the form to that URI and then have defaultUpCyc.php both process the form and reload the page.
  2. Use AJAX, and post the data to process-form.php, this wouldn't require any refresh at all.
  3. Do a redirect in process-form.php to defaultUpCyc.php.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文