PHP hack - 提交表单时打开两个网站

发布于 2024-11-05 21:03:45 字数 340 浏览 3 评论 0原文

当有人在我们的网站上填写表格并单击“提交”后,他/她将被定向到登陆页面。我想更改该流程,以便在提交时 (1) URL1 作为新窗口打开; (2) 用户从当前表单页面重定向到 URL2。

你能帮忙吗?

当前的代码片段 -

if(! isset($RedirectOnSuccess))
    $RedirectOnSuccess = 'oldURL';

我是一名技术新手,因此需要您的帮助将其拼凑在一起。我正在使用 MODx,网页本身使用以下内容调用 php 脚本 - [!FORM_SNIPPET? &RedirectOnSuccess=旧网址 !]

After someone completes a form on our website and clicks on submit s/he is directed to a landing page. I would like to change that flow so that upon submitting (1) URL1 opens as new window; and (2) user is redirected from current form page to URL2.

Can you help?

current code snippet -

if(! isset($RedirectOnSuccess))
    $RedirectOnSuccess = 'oldURL';

I'm a tech newbie so need your help in piecing it together. I am using MODx and the web page itself calls the php script with the following -
[!FORM_SNIPPET?
&RedirectOnSuccess=oldURL
!]

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

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

发布评论

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

评论(3

吾家有女初长成 2024-11-12 21:03:45

这可能取决于弹出窗口的上下文,但您可能会考虑使用侵入性较小且容易拦截广告的内容,而不是使用传统的弹出窗口,例如 lightbox 或页面内其他基于 ajax 的显示工具。您可以通过提交按钮上的单击事件触发灯箱,用它显示您的消息,然后在关闭或确认时提交表单。

避免查看表单结果页面依赖于 JavaScript 的解决方案,因为某些(不常见)用户可能会禁用它。如果按上述方式实现,此类用户将错过您的弹出窗口,但表单仍会通过。

您可以使用 jQuery 来实现此功能,而无需修改 MODx 用于生成表单的 php 代码,而是通过将 javascript 放入 xhtml 标头中,将单击事件附加到表单的提交按钮。例如:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script src="/colorbox/jquery.colorbox.js"></script>
    <script type="javascript">
    $("#FormID.input[type=submit]").click(function(e) {
      /* prevent form from submitting */
      e.preventDefault();
      e.stopPropagation();

      /* on colorbox close, submit form */
      $(document).bind('cbox_close', function(){
        e.submit(); // submit the form on close
      });

      /* open the colorbox */
      .colorbox({href:"http://example.com/url1"});
    });
    </script>

我在这里使用了 ColorBox ,但同样的想法应该适用于其他灯箱替代品。我没有对此进行浏览器测试,因此请务必根据需要进行测试和调整。

It likely depends on the context of your popup, but rather than using a traditional popup you might consider something less invasive and prone to ad-blocking such as a lightbox or other ajax-based display tools within the page. You can trigger the lightbox from a click event on the submit button, display your message with it, and then submit the form on close or confirm.

Avoid solutions where viewing the form result page is dependent on javascript as some (uncommon) users may have it disabled. If it is implemented as above, such users would miss your popup but the form would still go through.

You could use jQuery to implement this without modifying the php code that MODx uses to generate your form, and instead attach a click event to the form's submit button by putting javascript in the xhtml header. For example:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script src="/colorbox/jquery.colorbox.js"></script>
    <script type="javascript">
    $("#FormID.input[type=submit]").click(function(e) {
      /* prevent form from submitting */
      e.preventDefault();
      e.stopPropagation();

      /* on colorbox close, submit form */
      $(document).bind('cbox_close', function(){
        e.submit(); // submit the form on close
      });

      /* open the colorbox */
      .colorbox({href:"http://example.com/url1"});
    });
    </script>

I used ColorBox here, but the same idea should apply to other lightbox alternatives. I didn't browser test this, so be sure to test and adapt as necessary.

明媚如初 2024-11-12 21:03:45

考虑到弹出窗口拦截器的问题,您最好的选择是在表单上传时使用 HTML 定位新窗口。

<form target="_blank">

然后使用 JavaScript(可能通过弹出窗口中的 opener.location.href),您可以将主窗口重定向到另一个 URL。

Given problems with popup blockers your best bet is to target a new window with HTML on the form upload.

<form target="_blank">

Then using JavaScript (perhaps via opener.location.href in the popup), you can redirect the main window to another URL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文