Angular form's button can not be pressed - c#

I have a simple form for payment:
<form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8">
<input name="data" value="{{data}}" />
<input name="signature" value="{{signature}}" />
<input type="image" src="//static.liqpay.ua/buttons/p1ru.radius.png" />
</form>
The problem is that I can't press the button for payment, it's just don't work
I can assure you that the form is working I've checked this on C# with some changes:
<div class="container">
<form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8">
<input type="hidden" name="data" value="#ViewData["PaymentData"]" />
<input type="hidden" name="signature" value="#ViewData["Signature"]" />
<input type="image" src="//static.liqpay.ua/buttons/p1ru.radius.png" />
</form>
</div>
And all the parametress a passed correctly. It seems like Angular dont let me go to the link or sth like that. Help pls.
UPDATE
Ok I changed the form like this:
<form [formGroup]="payForm" (ngSubmit)="LiqPay()" #formDir="ngForm" novalidate>
<input formControlName="data" name="data" value="{{data}}" />
<input formControlName="signature" name="signature" value="{{signature}}" />
<button type="submit" class="btn btn-default" ng-href="https://www.liqpay.ua/api/3/checkout">go</button>
</form>
with LiqPay method:
LiqPay(){
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.payForm.value.data = this.data;
this.payForm.value.signature = this.signature;
this._http.post('https://www.liqpay.ua/api/3/checkout',
this.payForm,{headers}).map((response: Response) => response.json());
}
Now I guess the request is sent but it doesn't redirect on the desired link (https://www.liqpay.ua/api/3/checkout). So how can I change the form to redirect to this link with post data?

In the LiqPay method you are trying to send a post request to https://www.liqpay.ua/api/3/checkout. And in the button you have a ng-href attribute (trying to browser go to that url). I think that is not correct. You are sendind an asynchronous requets, and simultaneously sendind your user to that url.
I can understand, you are sending a form to a payment checkout? ok, you can use action in the form, exactly like the C# example.
I have tested your initial code
<form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8">
<input name="data" value="{{data}}" />
<input name="signature" value="{{signature}}" />
<input type="image" src="//static.liqpay.ua/buttons/p1ru.radius.png" />
</form>
And it works...
You can view it here:
https://jsfiddle.net/L1ruajzn/

Related

MVC ASP.NET Url.Action in form action, passing it form data

<form action="#Url.Action("PokemonSteps", "PokemonView", new { id = Model.Id, steps = steps })">
<input type="number" name="steps" min="1" max="#Model.userSteps">
<input type="submit">
</form>
This form is a number box from 1 to the amount of steps the user has.
When they submit the number in the box, I want to pass it to #Url.Action as the steps in the steps = steps part.
How do I go about that (sorry for the really stupid question)
<form action="#Url.Action("PokemonSteps", "PokemonView")" method="post">
<input type="hidden" name="id" value="#Model.Id">
<input type="number" name="steps" min="1" max="#Model.userSteps">
<input type="submit" value="Submit">
</form>
Please add Attribute method="post" and share your controller method signature also...
Try doing something like this:
#using (Html.BeginForm("PokemonSteps", "PokemonView", FormMethod.Post)){
#Html.TextBoxFor(m=> m.userSteps)
<input type="submit" value="Submit" />
}
Hope this Helps!!

Http POST method goes to test.com sometimes instead of localhost

I am experiencing a very strange behavior. I am doing a simple ASP .NET application that will upload a file to the server.
I have a simple form that does this:
<form class="form-horizontal" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="files" class="col-md-3 col-sm-4 control-label">Bestand *</label>
<div class="col-md-9 col-sm-8" ">
<input name="file" type="file" id="file" required />
<span >#ViewBag.TheMessage</span>
</div>
</div>
<div class="form-group">
<div class="col-md-9 col-sm-8 col-md-push-3 col-sm-push-4">
<input type="submit" class="btn btn-primary" value="Versturen" />
</div>
</div>
</form>
The strange thing happens with the POST, 9 of 10 times this POST goes to test.com instead of localhost. I sniffed it with firebug to discover this. The firebug looks like this:
The Controller.cs looks like this, and it's working fine when post reached:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
ViewBag.TheMessage = "Thanks, an e-mail will be sent shortly";
if (file.ContentLength > 0)
{
ViewBag.Message = "Your application description page.";
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return View();
}
Another strange thing is that if I just use an empty format cshtml file only with:
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="submit"/>
POST woks fine every time.
Thanks.
Check to see if you have any Javascript that is changing your forms action attribute. I would start by looking at onload, onsubmit, or on your submit buttons onclick method. If you're using jquery be sure to check your $(document).ready () function. This really could be anywhere in your js though so make sure you look everywhere.
Another culprit could be that you have a base tag in your html that looks something like <base href="http:www.test.com /> which will change all of your relative urls to go that base location

Form Submit in my code does not work on webbrowser control C#

This a html code in site that i want to use it in my web browser control C# :
<form name="frmWorkBookPrintTerm" action="WorkBookPrintTerm.asp" target="_blank" method="post">
<hr width="90%">
<input type="Hidden" name="strTermCode" value="912">
<input type="Hidden" name="strStudentCode" value="896325605">
<input type="Button" onclick="javascript:document.frmWorkBookPrintTerm.submit();" value="...">
<hr width="90%">
</form>
But It is not working. When i want to go ".../WorkBookPrintTerm.asp" directly website says you did illegal job and otherwise web browser control is not working.
Thank You.

postbackurl using get rather than post

I am developing a website using asp.net c# and I want to put a form inside the page. Now as aspx pages have the form tag I do not want to nest another form inside this as it will invalidate my html. But I need this form to use GET rather than POST. I know I can change the postback url in the asp:button. Can this be done without using logic in the codbehind?
Change the method to GET just for this form not every thing on the page
change the target to _blank if possible.
Example in html of what I want.
<form action="http://maps.google.co.uk/maps" method="get">
<p><label for="saddr">Your postcode</label>
<input type="text" name="saddr" id="saddr" value="" />
<input type="submit" value="Go" />
<input type="hidden" name="daddr" value="[destination]" />
<input type="hidden" name="hl" value="en" /></p>
</form>
you can use jquery to accomplish this
$(document).ready(function() {
$("#buttonId").click(function() {
$("#formId").attr("method", "get");
});
});
the above snippet, fires when the button with id 'buttonId' is clicked. it changes the method attribute of the form with id 'formId'
You can have multiple forms in an html. ASP.NET page also supports multiple form tags, however only one of then can be server side form (runat="server").
So I will suggest that you add another form tag within your page - some thing like
...
<body>
<form runat="server">
... server controls etc
</form>
<!-- your form -->
<form action="http://maps.google.co.uk/maps" method="get">
<p><label for="saddr">Your postcode</label>
<input type="text" name="saddr" id="saddr" value="" />
<input type="submit" value="Go" />
<input type="hidden" name="daddr" value="[destination]" />
<input type="hidden" name="hl" value="en" /></p>
</form>
</body>
</html>
Note that you cannot put any server side control in your html tag. So you have to use html controls and manage them within page code using Request object.

ASP.net - Problem with integrating form

The WorldPay payment gateway suggests using this HTML to take the customer to the payment page:
<form action="https://select-test.wp3.rbsworldpay.com/wcc/purchase" name="BuyForm" method="POST">
<input type="hidden" name="instId" value="211616">
<input type="hidden" name="cartId" value="abc123">
<input type="hidden" name="currency" value="GBP">
<input type="hidden" name="amount" value="0">
<input type="hidden" name="desc" value="">
<input type="hidden" name="testMode" value="100">
<input type="submit" value="To Payment!">
</form>
How to I put this form on my page? The problem is I have a master page which wraps the content pages content in the ASP.net form, I can't nest the forms.
This is a bit of a hack, but I have used this with paypal in the past. Basiscally just put and extra form above the form you are attempting to post as in the following:
<form>
</form>
<form action="https://select-test.wp3.rbsworldpay.com/wcc/purchase" name="BuyForm" method="POST">
<input type="hidden" name="instId" value="211616">
<input type="hidden" name="cartId" value="abc123">
<input type="hidden" name="currency" value="GBP">
<input type="hidden" name="amount" value="0">
<input type="hidden" name="desc" value="">
<input type="hidden" name="testMode" value="100">
<input type="submit" value="To Payment!">
</form>
Enjoy!
You can customize the HtmlForm to get this to work. I gave a code sample here:
How to get past embedding a html form for paypal buttons asp.net
http://www.codersbarn.com/post/2008/03/08/Solution-to-ASPNET-Form-PayPal-Problem.aspx
I've used this several times with master pages :-)

Categories

Resources