[英]Validate Form with PHP with Data Posting to Java Application
I have a Java application (servlet, written by someone else) that does some processing. 我有一个Java应用程序(servlet,由其他人编写),可以进行一些处理。 I have a PHP application (web site HTML that uses PHP in places) on top that posts data to the Java application:
我在顶部有一个PHP应用程序(在某些位置使用PHP的HTML网站),将数据发布到Java应用程序:
<form method="post" action="http://site/java" onsubmit="return validate(this)">
I have the JavaScript validating, as well onsubmit
. 我有JavaScript验证,以及
onsubmit
。
This works fine, but when I try and validate with PHP (in case JS is disabled), I run into problems. 这很好用,但是当我尝试使用PHP进行验证(以防JS被禁用)时,我遇到了问题。
I'm not sure how to do this. 我不确定该怎么做。 I've tried a few things but none has been really what I want.
我已经尝试了一些方法,但是没有一个是我真正想要的。 I want to be able to mimic the JS behavior but with PHP.
我希望能够模仿JS行为,但使用PHP。
It would be cool if I could do something like this: 如果我可以做这样的事情会很酷:
if ('POST' == $_SERVER['REQUEST_METHOD']) {
//do post to servlet
}
I've tried other things like this: 我已经尝试过其他类似的事情:
if (isset($_POST['field'])) {
//validate form with function
}
Part of the problem is that the Java application also does some validation and returns some parameters I can get. 问题的部分原因是Java应用程序还进行了一些验证并返回了我可以得到的一些参数。 I might use something like this to check these:
我可能会使用类似以下内容来检查这些内容:
if ($_GET['error'] == 'invalidEmail') {
$error = 'Please enter a valid email address.';
}
How would I do this? 我该怎么做? Can I use
Location
response header or does this not send POST
data? 我可以使用
Location
响应标头还是不发送POST
数据? If I set action=""
and post back to page, I can get the PHP to validate but obviously the whole point is to post to the Java application. 如果设置
action=""
并返回页面,则可以使PHP进行验证,但是很显然,整个过程就是将其发布到Java应用程序中。
You can use REST to post to your java application from php. 您可以使用REST从php发布到Java应用程序。 More specifically the cURL library.
更具体地说,cURL库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.