[英]Nested old-style form with Angular
I'm facing a tricky problem: I have to make an old style form with action attribute inside a ng-form. 我面临一个棘手的问题:我必须制作一个带有ng-form内的action属性的旧样式表单。
The reason I'm doing this is that the POST request from the old-style form goes to another website, and the user should be "redirected" (in a new page actually) to the result of the POST request (which makes kind of login). 我这样做的原因是,旧式表单中的POST请求转到了另一个网站,并且应该将用户“重定向”(实际上是在新页面中)到POST请求的结果(这使得登录)。
I can simulate the old-style form from javascript but so the browser popup blocker will catch it and it has to be as easy as clicking a link. 我可以用javascript模拟旧样式,但是浏览器弹出窗口阻止程序会捕获它,它必须像单击链接一样简单。
I can't touch the outter ng-form because it comes from a framework. 我无法触及外部ng-form,因为它来自框架。
So what I have is: 所以我有:
<div ng-form>
...
...
<form action="old_website.com/index.php" method="post" target="_blank">
<input type="hidden" name="field1" value="value1">
<input type="submit" value="Submit">
</form>
...
...
</div>
I can't find a way to make this work :) Hope you can help. 我找不到使这项工作有效的方法:)希望您能提供帮助。
[edit] Ok I feel stupid. [编辑]好吧,我觉得很愚蠢。 It seems you can have a button that calls a function to simulate and submit the form without having trouble with the browser popup blocker...
看来您可以有一个按钮来调用一个函数来模拟和提交表单,而不会遇到浏览器弹出窗口阻止程序的问题。
It also seems it does not work with Firefox. 似乎也不适用于Firefox。
What I'm doing is: 我正在做的是:
HTML:
<button ng-click="submitForm()">Submit</button>
JS:
$scope.submitForm = function() {
var form = $('<form>', {
action: 'old_website.com/index.php',
type: 'post',
target: '_blank'
});
form.append($('<input>', {name: 'field1', value: 'value1'}));
form.submit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.