使用Javascript和PHP将表单数据提交到两个位置? [英] Submitting form data to two locations using Javascript and PHP?

查看:129
本文介绍了使用Javascript和PHP将表单数据提交到两个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个订单,其中有几个文本区域和一个PayPal立即购买提交按钮。我希望PayPal按钮像平常一样工作,将订单提交给PayPal,但我也希望使用同一个按钮来收集表单中的数据并通过电子邮件发送。然而,为了做到这一点,按钮需要有两个操作:发送数据到PayPal,并将数据发送回我的php页面。



看起来像这样是一个常见问题,目前还没有明确的解决方案,但仅使用PHP。由于我只需要表单中的数据,所以我想我可以用Javascript来获取。我想我可以在paypal按钮上放置一个onClick事件,它会调用一个包含发送电子邮件所需PHP的JavaScript函数。



这可能吗?我是这样想的吗?



编辑
好​​的,我不想挖掘PayPal API,因为我不熟悉贝宝开始。我正在考虑另一种解决方案,该解决方案尚未发挥作用,但它可能具有潜力。



标准PayPal按钮代码使用input type =image作为按钮。我在该输入标记周围放置一个链接元素,并链接到一个javascript函数。例如:

 < a href =javascript:submitForm()> < input type =image src = ...>< / a> 

我有这样设置的表单:

 < form name =userInfoaction =sameFile.phpmethod =post > 

其中sameFile.php只是该行所在的当前php文件的名称in。



然后在同一个代码文件中的其他地方:

 < script type =text / javascript> function submitForm(){document.forms [userInfo]。submit();}< / script> 
pre>

其中userInfo是包含所有用户输入框的表单。请注意,userInfo不是包含PayPal按钮的表单,因此可能是问题。 ..

无论如何,这一切似乎工作,但我不知道如果贝宝订单正在经历或不,我只是被重定向回到相同的PHP页面。

接下来我想用PHP来提取应该在POST数组中的数据,我输入一些测试回声报告POST值,但是一旦我添加了这段代码,页面就不会加载。我究竟做错了什么?是否有一个特定的地方,我应该把解析表单中的数据的PHP? 解决方案

你想发送一个订单完成邮件?



如果是这样,编写代码发送邮件在paypal的成功页面(返回页面在您的服务器) - 这是实际做法。 / p>

I have an order form that has several text areas and a single PayPal "Buy Now" submit button. I would like the PayPal button to work like usual, submitting the order to PayPal, but I would also like the same button to collect the data in the form and send it off in an email. In order to do that, though, the button would need to have two actions: sending data to PayPal, and sending data back to my php page.

It seems like this is a common problem, with no clear solution yet using solely PHP. Since I only need the data from the forms, I thought I could grab that with Javascript. I thought I could put an onClick event on the paypal button, which would call a JavaScript function that contains the PHP needed to send an email.

Is this possible? Am I way over-thinking this?

EDIT Ok, so I don't want to dig into the PayPal API, since I am not comfortable with PayPal to begin with. I am thinking of another solution, which has not yet worked, but it might have potential.

The standard PayPal button code uses an input type="image" for the button. I am placing a link element around that input tag, and linking to a javascript function. For example:

<a href="javascript: submitForm()"> <input type="image src= ...> </a>

I have a form set up like this:

<form name="userInfo" action="sameFile.php" method="post">

Where "sameFile.php" is just the name of the current php file this line resides in.

Then elsewhere in the same code file I have:

<script type="text/javascript"> function submitForm(){ document.forms["userInfo"].submit();}</script>

Where userInfo is the form with all my user input boxes. Note that "userInfo" is NOT the form which contains the PayPal button, so that might be the problem...

Anyway, this all seems to work, though I have no idea if the PayPal order is going through or not. I just get redirected back to the same php page.

Next I want to use PHP to extract the data that SHOULD be in the POST array. I enter a few test echos reporting the POST values, but the page does not load at all once I add this code. What am I doing wrong? Is there a specific place I should be putting the PHP that parses the data from the forms?

解决方案

Do you want to send a order completion mail ?

If so, write code to send mail in success page of paypal(return page in your server) - This is the actual way of doing it.

这篇关于使用Javascript和PHP将表单数据提交到两个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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