使用PHP cURL在新窗口中打开结果 [英] Use PHP cURL to open result in new window

查看:192
本文介绍了使用PHP cURL在新窗口中打开结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用cURL访问第三方应用程序的PHP表单。我也有我自己的验证窗体。目前,当您触发表单时,它被发送到 $ _ SERVER ['PHP_SELF'] ,如果有问题,验证错误出现在表单的顶部。如果没有问题,变数会传送到第三方应用程式,浏览器会将使用者导向该应用程式,以继续处理。

I've a PHP form that uses cURL to access a third party application. I've also got my own validation on the form. Currently when you fire the form it is sent to $_SERVER['PHP_SELF'] and if there's an issue, the validation errors appear at the top of the form. If there's no issue, the variables are sent to the third party app and the browser takes the user to that app to continue the process.

现在,客户想要这份表单在新窗口中打开。我已经将target = _blank添加到表单元素,但是这会导致一个新窗口打开,即使窗体无效(即有验证错误)。所以我需要的形式,直到它实际提交到第三方应用程序。

Now, the client wants this form to open in a new window. I've added target=_blank to the form element, but this causes a new window to open even when the form is invalid (i.e. there are validation errors). So I need the form to stay where it is until it is actually submitted to the third party app.

任何人都知道如果有一个cURL变量,重定向到一个新的窗口?我不能在手册中找到任何东西。

Anyone know if there's a cURL variable that does a redirect to a new window? I can't seem to find anything in the manual.

推荐答案

你混淆了服务器端和客户端代码。

You're confusing server-side and client-side code.


  • cURL是服务器端。当触发cURL(在PHP中)时,您的表单已经发布,因此在客户端执行操作太晚了。

  • Javascript是一个客户端脚本语言。

  • cURL is server-side. When cURL is triggered (within PHP), your form has already been posted, it's too late to act on the client side.
  • Javascript, however, is a client-side scripting language. You can use it to validate a form.

现代Web应用程序的一个好习惯是使用Javascript预先验证表单,然后只有在表单被验证时才发布到PHP脚本。如果您需要服务器端功能来验证您的表单,那么您可以使用 Ajax 。有一些非常好的库,如 jQuery ,这使得现在不痛苦(甚至发布整个表单与Ajax,而不离开页面)。

A good practice in modern web applications, is to pre-validate a form using Javascript, then post to the PHP script only if the form is validated. If you need server-side features to validate your form, then you might post some data and request information from the server with Ajax first. There are some very good libraries such as jQuery which make that painless nowadays (even posting the whole form with Ajax without leaving the page).

一个老的替代方法是发布到PHP脚本,验证表单,然后输出一些Javascript标签来打开一个新窗口,如果窗体是有效的。但是,现在任何浏览器内置的弹出式窗口拦截器都会阻止。

An old alternative would have been to post to the PHP script, validate the form, then output some Javascript tag to open a new window if the form is valid. However, this would now be blocked by any browser built-in popup blocker.

这篇关于使用PHP cURL在新窗口中打开结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆