On button click create dynamic form, autofill the data and post on url in Angularjs

I am using AngularJS, I am trying to implement payment gateway in my web application and stuck at some step

So, at first step I have JSON data , Request method and Url on which I need to post the data.

JSON data sample : { "key1" : value1, "key" : value2 }

Request Method : POST

url : myPaymentGatewayUrl

My requirement is : When I click on button Make Payment, it should create a dynamic form and auto fill the data which I have in my JSON and and post that form data on url. This process should happen under the hood and I should redirect to payment gateway page.

JS function

proceedToPayemnt: function(lead_id){

    var Payment = this;
    var payment_provider = this.payment_provider;
    var selected_payment_provider = this.selected_payment_provider;
    var user_profile = UserProfile.user_profile;

    var answer = selected_payment_provider[payment_provider.psp_id];
    
    if(answer == 1){
        var lead_id = 145282;
        Payment.offlinePayment(lead_id);
    }else{
         var lead_id = 145282;
        Payment.onlinePayment(lead_id);
    }                                                                                                                                                                                
   },

Answers


You can use ng-repeat to create controls from your JSON sample data, something like this will do that. If you dont want to display the form you can use ng-hide to hide the form, and onclick of the proceedToPayment button you can fire submitBtn click. I hope that should solve this.

<form action="URLHERE"  method="POST">
  <div ng-repeat="(key,value) in sampleData">
    <input type="text" id="{{key}}"  ng-model="sampleData[key]" />
    </div>
  <button id="submitBtn" type="submit">submit</button>
</form>

Thanks for the solution. I referred this Programmatically submitting Angularjs form to an external url and it worked.


Need Your Help

Can you suspend a Java app and get a snapshot of it's threads from within the app?

java multithreading runtime monitoring

I'm looking at writing monitoring code that runs inside a Java application and periodically takes a snapshot of running threads and displays some call stack information on each.

Invalid Argument Running Google Go Binary in Linux

linux go

I’ve written a very small application in Go, and configured an AWS Linux AMI to host. The application is a very simple web server. I’ve installed Go on the Linux VM by following the instructions in...