Pre fill and submit a form in in a view with AngularJS

I have this very simplified AangularJS app. It is working very well.

Now, I need to fill some fields and submit the form directly from the view, without user interaction.

Here's the Javascript code (once again, simplified and I removed many other elements)


    mainApp.controller("resultsController",FormController);
    function FormController($scope,APIService) {
        $scope.result ="";
        $scope.search = { keywords: "",
                          result:1,
                          term: "-1",
                          subject: "-1"};
        $scope.searchNow = function() {
            APIService.getTheResults($scope);
        } // $scope.searchNow

    }

    function getResults($http) {
        var results = {};
        url = "...";

        results.searchResults = function() {
            var lurl = url + "a=s";
            return $http( {method: "JSONP", url:lurl} );
        } // results.searchResults

        results.getTheResults = function(scope) {
            var lurl = url;
            $http({
             method: 'POST',
             url:lurl,
             data:jQuery.param(scope.search),
             headers:{'Content-Type':'application/x-www-form-urlencoded'}})
                .success(function(lresponse){
                    var theResponse;
                    theResponse = eval(lresponse);
                    scope.mydata = theResponse.data[0]
                })
                .error( function(data,status) {
                    scope.result = status;
                });
        } // results.getTheResults
        return results;
    } // function getResults($http)

Answers


Try using form method post. So change your form tag to:

<form id="search_form" name="search_form" ng-submit="searchNow()" method="post">

As described in this chapter at w3schools, when using post method the data will not be shown in the url.

"POST offers better security because the submitted data is not visible in the page address."


Solved: I noticed that the page was trying to submit the form too quickly. First, I set a timer to 5 seconds after the form loaded and then call the click function of the submit button. Then, I just used a window.unload function to be called when the entire DOM is created:

window.onload = function(){ document.getElementById('submit-button').click(); };

Need Your Help

Selenium test can be started via maven only. Fails with NullPointer when starting using TestNG xml file (because system variable is 'null')

java maven nullpointerexception system-properties maven-failsafe-plugin

The issue is the following - if I launch my autotests via maven(from command prompt OR eclipse), then they run without issues. If I try to launch via testng.xml(from eclipse), then my tests fail with