简体   繁体   中英

<keygen> element empty in POST after form submit

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.

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();     
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM