Form inside angular component does not submit - javascript

I have a classic html form element which works fine when I insert it into the index.html of an angular application. A click on the button submits the form. If I insert the same form in an angular component html file, it is rendered as well but when I click the button, nothing happens.
<form method="post" action="https://blub.shtml" id="form" name="form" target="_parent">
<input type="hidden" name="data" value="data" />
<input type="submit" value="Send" />
</form>
Why does this happen and how can I fix it?
EDIT: I cant use (ngSubmit) because of the CORS policy of the server.

Try this approach to see if it work
<form method="post" action="https://blub.shtml" id="form" name="form">
<input type="hidden" name="data" value="data" />
<button type="submit"/>Send</button>
</form>

Try this
<form ngNativeValidate (ngSubmit)="onSubmit()" #form="ngForm">
and in onSubimit method you can to whaterver you want.

Related

Can we submit an html post form in react-native?

I have a question if we can submit an html post form with Linking in react-native. If yes how we can submit it?
I want to submit it to default browser (not with webview) and here is html form:
<form method="POST" target="..." id="..." :action="videoConferenceUrl">
<input type="hidden" name="target" value="..."/>
<input type="hidden" name="requestOrigin" value="..."/>
<input type="hidden" name="username" :value="..."/>
<input type="hidden" name="password" :value="..."/>
<input type="hidden" name="eventID" :value="..."/>
</form>
Please write every way how we can submit that form in the default browser.
Thanks in advance.

Why does form action call not keep input file when using back button?

function validate_form()
{
//..... validation and other stuff will go here ...
}
<form name="read" id="read" action="test2.php" method="post" enctype="multipart/form-data" onsubmit="return validate_form();">
<input type="file" name="pac" />
<input type="submit" name="submit" value="Submit" />
</form>
In the above example, if you hit the browser back button, the input file remains.
function validate_form()
{
//..... validation and other stuff will go here ...
document.read.action = "test2.php";
}
<form name="read" id="read" action="" method="post" enctype="multipart/form-data" onsubmit="return validate_form(this);">
<input type="file" name="pac" />
<input type="submit" name="submit" value="Submit" />
</form>
In the above example, if you hit the browser back button, the input file is cleared. Why is that? Is the only way to get around this is to save the input into a cookie or session variable? If so, not sure how to save a file.
I have a reason to use the call from JS. I removed most of the code for the above examples. This is happening under Chrome and Firefox. Didn't test others.

submit form as soon as file was selected

I have following html form:
<form method="POST" action="uploadImage" enctype="multipart/form-data">
<input type="file" class="file" name="file"/>
<input type="submit" value="Upload">
</form>
I see two things on page
1 - file selector
2 - upload button
I want to avoid submit button and form should be submitted right after file was selected.
Can you help me?
Maybe this helps you:
$('.file').change(function(){
$('form').submit();
});
with javascript..
<form method="POST" name="myform" action="uploadImage" enctype="multipart/form-data">
<input type="file" class="file" name="file" onchange="document.forms['myform'].submit();"/>
</form>

How to prevent page redirection/refresh after form submit, while preserving file input? Jquery

I have a file upload form as follows:
<form id="upload" action="someurl" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" />
<input type="submit" value="submit" />
<form>
Problem is that every time I submit the form I will be redirected to the form's action url.
How do I submit this form while still staying on the same page? Using ajax or preventDefault won't work as I will lose the file stream.
Rendy
Provided you have an iframe on your page that's hidden,
<iframe id="hidden-iframe"></iframe>
then add a target to your form:
<form id="upload" action="someurl" method="post" target="hidden-iframe" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" />
<input type="submit" value="submit" />
<form>
you're done !

How To Submit An HTML Form Using PHP?

This is what I am trying to do without success :
<form name="something" action="ht.php" method="post">
Submit
</form>
When I click on the link I want to post the value helloworld to ht.php. How can I do this?
You can't just do document.url.submit(), it doesn't work like that.
Try this:
<form id="myForm" action="ht.php" method="post">
<input type="hidden" name="someName" value="helloworld" />
Submit
</form>
That should work!
Using jQuery, its rather easy:
$('form .submit-link').on({
click: function (event) {
event.preventDefault();
$(this).closest('form').submit();
}
});
Then you just code as normal, assigning the class submit-link to the form submission links:
<form action="script.php" method="post">
<input type="text" name="textField" />
<input type="hidden" name="hiddenField" value="foo" />
Submit
</form>
I find this method useful, if you want to maintain an aesthetic theme across the site using links rather than traditional buttons, since there's no inline scripting.
Here's a JSFiddle, although it doesn't submit anywhere.
try
<form id="frmMain" action="ht.php" method="post">
Submit
</form>
Try this,
<!-- you need to give some name to hidden value [index for post value] -->
<form name="something" action="ht.php" method="post">
<input type="hidden" name="somename" value="helloworld" />
Submit
</form>
Also try this
<!-- you need to give some name to hidden value [index for post value] -->
<!-- also you can use id to select the form -->
<form name="something" action="ht.php" method="post" id="myform">
<input type="hidden" name="somename" value="helloworld" />
Submit
</form>
You could add a hidden field on the page (set it's name property), set it's value to helloworld.
Then in your hyperlink's onclick call form.submit()

Categories