javascript - PHP, Submit form on load - Stack Overflow

I want to submit a form immediately when a PHP file is visited in the browser.How can I do this: Pref

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
Add a ment  | 

3 Answers 3

Reset to default 2

Invoke 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331660a4622906.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信