last day (14 days later) » 

6:16 AM
0
Q: Form submission could not get full data when I use Angular to filling data before submission

Chiến NghêI want to submit a form data to an outside url, but I got problem when I used angular for filling data and submission. Here is my form <form name="frm" id="myForm" method="post" action="http://an-outside-url.com"> <input type="hidden" name="NAME" ng-model="NAME"> <input type="hi...

 
What is a trigger to submit? Do you want to submit in a initializing process of your controller?
 
Yes, in the initializing process.
But i see it's the same if i trigger event from elsewhere, maybe a button click for example
 
If you submit form on click event of a button, you could get what you want.
BTW I recommend you to use $http.post instead of $('#myForm').submit() as you do. If you insist to use it, you could try to wrap this line with $timeout service.
 
Ah, i understand, but i want to do filling data then submit in the same thread.
 
Would you like to explain the reason why you insist your way? I think the answer depends on the reason.
 
6:16 AM
Ah, i need to integrate with a payment gateway. The submission should be done automatically instead of triggered from an user action like button click for example
 
I guess click event of some button (for example, 'PAY') might make your controller initialize. Could you move submit logic into 'PAY' button click event handler?
Or I recommend you to implement payment logic in server instead of client logic.
I mean you should rethink the location of implement payment logic. If you don't want big change of your exsting code, as I mentioned above, $timeout service would help you with minimum change.
 
Yes
thank you
because of customer's requirement
we could not invent a Pay button on screen
About change logic to server side
it's requirement from payment gateway that they do not accept it
we must use client-server model for data submission
because after submission, customer will be redirected to payment gateway's page
I think of timeout also
but it's not a complete solution
just work around
because if I set time out is 1s
I could get delay
But I am not sure about all fields are set
I wonder angular could provide us a mechanism
so that we could detect the digest cycle is finished
it's what i am looking for
 
6:59 AM
Thanks for your explanation.

About changing logic to server side.

You could implement with follow steps.

1. call server logic automatically in your controller initializing process.
2. post form data to payment gateway in your server logic.
3. get response from payment gateway and response 302 to your client.


About $timeout service.

I agree $timeout service is not perfect solution. But I guess $timeout service allows angular to run digest cycle before you post form.(You need test.)
So even if you set 1ms, I guess post data could have the data you set in your controller.
 
Yes, thank you! I am looking forward to your perfect solution
!
 

last day (14 days later) »