Laravel 5:如何将数据重定向到外部资源表单控制器
问题描述:
我想将用户发送到付款门.通常可以通过以下形式进行制作:
I want to send user to payment gate. Normally it could be made by this form:
<form method="post" action="https://demo.moneta.ru/assistant.htm">
<input type="hidden" name="MNT_ID" value="12345678">
<input type="hidden" name="MNT_TRANSACTION_ID" value="000001">
<input type="hidden" name="MNT_CURRENCY_CODE" value="USD">
<input type="hidden" name="MNT_AMOUNT" value="123.45">
<input type="submit" value="Pay">
</form>
用户按付款",然后重定向到付款门.
User press "Pay" and redirect to payment gate.
但是我想实现这个工作流程:
But I want implement this workflow:
- 用户输入交货信息,付款方式等
- 之后,他按付款",然后按
- 首先,我要存储数据(我在控制器中进行存储)...
- ...,然后我要将用户重定向到付款门. (我不清楚)
问题是:如何将用户从控制器重定向到外部资源(方法应该是POST,我需要发送一些数据,例如MNT_ID等(请参见上面的表单示例)?
The question is: how to redirect user to external resource from controller (method should be POST, and I need do send some data such as MNT_ID, etc. (see form example above)?
答
我认为这是您要寻找的:
I think this is what you are looking for:
调用您的功能控制器:
public function redirectPOST(){
//params
$USERNAME='username';
return view('your vie', compact('USERNAME'));}
然后在您看来:
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript">
function closethisasap() {
document.forms["redirectpost"].submit();
}
</script>
</head>
<body onload="closethisasap();">
<form name="redirectpost" method="POST" action="http://URL">
<input type="hidden" id="USERNAME" name="USERNAME" value="{{$USERNAME}}">
</form>
</body>
</html>