Hello, Folks!!
I am not very experience. I would really appreciate some help as follows:
Goal: Run 2 actions associated with 1 submit, just have to add URLs and they will pull out all the necessary info they need from the form.
Constraints: No access to Database, No Ajax and No PHP.
Problem: Nothing happens even when I use <input type="button" value="submit" onclick="OnBtn1(); OnBtn2();">
I also tried these with no luck:
Two onClick actions one button
Submit single form to two actions
HTML Code:
<script type="text/javascript">
function postToUrl () {
document.Form1.action = "https://dB2.com/cgi-bin/b.cgi?"
document.Form1.submit();
}
</script>
<form id=" Form1" method="POST" action="https://dB1.com/cgi-bin/a.cgi?" onsubmit="postToUrl();">
<input type="text" id="field1" name="field1">
<input type="text" id="field2" name="field2">
<input type="button" value="submit" name="sdb">
</form>
Can someone please help me? Thank you!
The best solution would be to use ajax, to send the form twice on the submit event.
Maybe you can try to add a hidden form with mirrored values but different action url. This way, when you submit the form it submit the hidden one too.
Related
Not sure how I did this last time or else I wouldnt asking here but here is what I'm trying to do.
I have the usual basic form with a javascript function that will submit the form. Question is that after the form is submitted, I have an if statement in PHP that echos a that the form has been submitted. Any help would be greatly appreciated.
//PHP
if($_POST['submitDelete']){
echo "welcome, You form has been submitted";
}
//HTML
<form id="form_id" action="" method="POST">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="hidden" name="submitDelete" TYPE="submit">
</form>
<button type="button" onclick="myFunction()">Submit</button>
//JAVASCRIPT
<script>
function myFunction() {
document.getElementById("form_id").submit();
}
</script>
I can't seem to trigger the if statement in PHP. I also tried using the form name in the if statement and that didnt work either.
A form element must be told where to submit its data to when the submit event takes place. This is accomplished by setting the action attribute value for the form. Leaving that attribute empty does not implicitly set the form to post back to the current page. So, if you want to have a single page form/form processor, you need the action to be set to the current page file name:
<form action="currentPageFileName.php" method="post">
Next, there's no reason a single page can't have multiple forms on it. In that case you would need multiple submit buttons, each tied to a specific form. For this reason, you can't just drop a submit button anywhere on the page that you like unless you add the form attribute to the button to tie it back to the form it is supposed to trigger the submit for. Also, if you simply place the submit button within the form element it "belongs" to, you don't have to worry about this.
Also, you have some invalid HTML with:
<input type="hidden" name="submitDelete" TYPE="submit">
An element may not have the same attribute repeated within it (the case that you type the attribute in makes no difference since HTML is not case-sensitive). So, that code would wind up simply creating a submit button.
Lastly, if all you want to do with your submit button is cause its related form to be submitted, there is no need for JavaScript at all. That is what submit buttons do by default.
So, in the end, you can get rid of the JavaScript in your code completely and change your HTML to this:
<form id="form_id" action="currentFileName.php" method="POST">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="hidden" name="submitDelete" value="true">
</form>
<button type="submit" form="form_id">Submit</button>
Let there be a search form with quite many of the input fields. The user may either click:
[Search] and GET the list of the results,
[Save search criteria] for future use and POST the form content to be stored on server (I'm not interested in storing locally in cookies or so).
How do I achieve that? I've only found solutions to make two types of POST request on two separate buttons.
Maybe a JavaScript onclick function to set <form method="??"> right before its submitted? Would that work?
In HTML5, the <input> element got some new attributes
<input type="submit" formmethod="post" formaction="save.php" value="Save" />
<input type="submit" formmethod="get" formaction="search.php" value="Search" />
The same attributes are valid for <button>
Yes you can change form method before submit form using jquery
<form method="POST" id="myForm">
<button onclick="changeMethod()">submit</button>
</form>
Function changeMethod in jquery
function changeMethod(){
$("#myForm").attr("method", "get");
}
this might be a very simple question, but cannot really figure it out. If I have a simple form
<form action="demo_form.asp">
<input type="text" name="user">
<input type="submit" value="Submit">
</form>
with a quite long request, because it triggers an external API, how would it be possible to trigger JS and show a loading icon in the meanwhile.
$('input[type=submit]').on('click', this, FnToShowEl)
does not work.
Any idea?
You might want to submit your form like:
$('form').on('submit', function() {
showLoader();
});
I have a form with some input buttons(type="text") and submit button. I also want to implement rate function, so I have found plenty of jQuery plugins (for example this one http://www.jqueryrain.com/?ws9XtnKy). But I can't understand, how can I send rate value to .php handler together with other data, which is in a different form, when submit button is clicked. Can somebody explain it to me? Do you have any ready solutions?
<form method="POST" action="test.php">
<input type="text" name="booktitle" placeholder="Title"/>
<input type="submit"/>
</form>'
<script>
var x;
</script>
I have applied ParsleyJS validation to a form that has multiple submit buttons that perform various tasks. I only want the validation to occur for one of the submit buttons, is this possible? if so, how?
For a pared down example:
<form name="aspnetForm" method="post" action="page.aspx" id="aspnetForm" data-validate="parsley">
<input type="text" id="text_for_example" data-required="true"/>
<input type="text" id="text_for_example2" data-required="true"/>
<input type="text" id="text_for_example3" />
<input type="submit" id="ClearsTheTextBoxes"/>
<input type="submit" id="SavesData" />
</form>
Ideally I want it to validate only on the "SavesData" submit, not on the "ClearsTheTextsBoxes". is this possible using ParsleyJS?
Thanks!
Note:
I cannot change the type any of the submit buttons to function differently; please do not suggest this. The "ClearsTheTextsBoxes" must remain a submit button.
to do so, you'll have to remove data-validate="parsley" from your form tag, and add a custom js function on click on the desired button. Then in this function, simply to a $('aspenetForm').parsley('validate');
Best