0

I have a form as follows:

<form name="signupForm" id="signupForm" method="POST" ng-submit="create()">
            <input type="hidden" name="username" id="username" value="mtest">
            <input type="text" placeholder="Account name" name="webid" ng-model="account.webid" ng-focus="isFocused" ng-blur="isFocused = false"><br>
            <input type="text" placeholder="Full name" name="name" ng-model="account.name"><br>
            <input type="text" placeholder="Email" name="email" ng-model="email"><br>
            <input type="text" placeholder="Picture URL" name="pictureURL" ng-model="account.pictureURL"><br>
            <keygen id="spkac" name="spkac" challenge="randomchars" keytype="rsa" form="signupForm" hidden>
            <br>
            <input type="submit" id="submit" value="Submit">
</form>

The data is passed to the POST as follows:

$http({
          method: 'POST', 
          url: uri,
          data: $("#signupForm").serialize(),
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'application/x-x509-user-cert'
          },
          withCredentials: true
        }).

Once I submit the form to send it with a POST http request, I get the $("#signupForm").serialize() as follows:

"username=mtest&webid=mtest.databox.me%2Fprofile%2Fcard%23me&name=M+Test&email=mtest%40test.com&pictureURL=picURL&spkac="

Why is the keygen element always empty? Is there anything wrong I am doing?

Any answer is appreciated, thanks in advance.

mzereba
  • 2,467
  • 5
  • 26
  • 40
  • "Deprecated This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time." — https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen – Quentin Dec 09 '15 at 11:23
  • @Quentin Are you aware of any alternative to do this? – mzereba Dec 09 '15 at 11:27
  • I mean since it is currently working, I was wondering what is currently wrong that it might be going on? – mzereba Dec 09 '15 at 13:24

1 Answers1

0

Solved!

So preparing an HTTP Request to do that doesn't work for some reason. Instead the form action needs to be set and form submitted straight away in order to send the keygen with it. Here the solution:

in the Template the action is parametrical:

    <form name="signupForm" id="signupForm" method="POST" action="{{actionUrl}}">
     ...
    <input type="submit" id="btnSubmit" value="Submit" ng-click="completeForm()">

and the Controller sets the action and submits the form as follows:

$scope.completeForm = function () {
        $scope.actionUrl = "https://" + document.getElementById("username").value + "...";
        document.getElementById("signupForm").submit();     
};
mzereba
  • 2,467
  • 5
  • 26
  • 40