1

I'm facing a tricky problem: I have to make an old style form with action attribute inside a ng-form.

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).

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.

I can't touch the outter ng-form because it comes from a framework.

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.

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();
}
ValLeNain
  • 2,232
  • 1
  • 18
  • 37
  • not sure can you disable the ng-form but another way to reach your need is to close the
    tag before your old style form so your form is not included inside the ng-form tag.
    – Roy Pun Feb 05 '16 at 11:09
  • I don't actually think there is a tag to force a link to open in a new tab instead of a new window because it's based on browser preferences. More info [here](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target) – Alessandro Cifani Feb 05 '16 at 11:10
  • @RoyPun : it should stay inside the ng-form, because this button is actually part of a bigger form. There are fields before and after the old-style form that should be submitted by the ng-form. – ValLeNain Feb 05 '16 at 11:13
  • @AlessandroCifani : the problem is not really to open it in a new tab instead of window, I think the popup blocker will catch it in both cases. – ValLeNain Feb 05 '16 at 11:14

1 Answers1

0

Since the edit solved the first problem I had, I'll close this question and open another for the Firefox problem.

Thanks guys :)

[edit] This solved the problem with firefox.

Community
  • 1
  • 1
ValLeNain
  • 2,232
  • 1
  • 18
  • 37