I want to submit a form immediately when a PHP file is visited in the browser. How can I do this: Preferably in jQuery.
Details:
I have a form that once submitted inserts some data into a database and sends the user to a separate page. On the separate page, I have code for another form that then directs users to pay for whatever they have selected.
I don't want the user to have to click submit on the second form in order for them to pay. So is there a way to make that form submit automatically and thus direct the user to the payment stage?
I want to submit a form immediately when a PHP file is visited in the browser. How can I do this: Preferably in jQuery.
Details:
I have a form that once submitted inserts some data into a database and sends the user to a separate page. On the separate page, I have code for another form that then directs users to pay for whatever they have selected.
I don't want the user to have to click submit on the second form in order for them to pay. So is there a way to make that form submit automatically and thus direct the user to the payment stage?
Share Improve this question edited Apr 2, 2015 at 16:50 Eric Leschinski 154k96 gold badges422 silver badges337 bronze badges asked Oct 23, 2011 at 17:04 Alex SaidaniAlex Saidani 1,3172 gold badges16 silver badges32 bronze badges 1- 2 So why don't you redirect the user to the payment stage in the first place? – Jon Commented Oct 23, 2011 at 17:07
3 Answers
Reset to default 2Invoke the submit
method:
$("#formID").submit();
So, at your second page:
<script>
$(function(){
$("#your-formID").submit();
});
</script>
you can do this
<body onload="submitForm()" ></body>
<script>
function submitForm()
{
document.frm.submit();
}
</script>
frm is name of form
Why does that form exist if it is submitted automatically? Make the first form redirect directly to the third page and handle the rest on the server. No need to send the data to the client if it is not used there. And automatically posting using Javascript may not work on each client. Eliminate the risk by doing it server side.