I have a legacy backend server that processes form data as request parameters. We are putting angular2 on the front end. I want to submit the angular2 form so that all fields go as request parameters so that the legacy backend doesn't have to be changed. To do this I have :
<form ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST">
But I also want to use the angular2 form validation on the submit button:
<form #f="ngForm" ngNoForm action="http://localhost/config/api/v1/angular/submit" target="_blank" method="POST">
<button type="submit" [disabled]="!f.form.valid" class="small round">Submit</button>
However this does not work - angular2 complains about having #f="ngForm" when ngNoForm is declared.
Is there any way to be able to do angular2 form validations as usual, and also submit the form as regular request parameters?
Form validation is an important part of web application. It is used to validate whether the user input is in correct format or not.
It's simply a directive exported from FormsModule which gets automatically added to all <form> tags in your Angular templates once you import the module. Behind the curtains, the ngForm directive creates a top-level FormGroup instance and binds it to your <form> tag to enable you to work with the form.
NgFormlink. Creates a top-level FormGroup instance and binds it to a form to track aggregate form value and validation status.
Force submit using pure JS, this worked for me:
<form ngNoForm [formGroup]="myForm" action="http://test.local/process_post.php" target="_blank" method="POST">
<input formControlName="alpha" name="alpha"/>
<input formControlName="beta" name="beta"/>
<button type="submit" [disabled]="!myForm.valid" onclick="submit()">SEND</button>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With