Php form developed by WeChat: two solutions are automatically submitted in WeChat, and php form

Source: Internet
Author: User
Tags php form

Php forms developed for automatic submission of two problem solutions, php forms

Preface:

Recently developed. On the PHP page accessed in, there is a form on the page. The test finds that the form is automatically submitted twice, resulting in a process error.

Cause

No reason is found for the moment, but it is suspected that it is related to its own mechanism.

Solution

With session, a random number post is calculated every time a form is submitted. When submitting a page Processing Form, first determine whether the session exists. If the session does not exist, save the session. If the session exists, it is compared with the post random number. If the session is equal, it indicates repeated submission.

Sample Code:

Form part

<Div class = "odform"> <form action = "#" method = "post"> <div class = "input-group"> <label for = "amount_id"> amount </label> <input type = "text" name = "amount" id = "amount_id" placeholder = "unit: RMB, accurate to score, for example: 12.66 "pattern =" ^ ([1-9] + (\. [0-9] {2 })? | 0 \. [1-9] [0-9] | 0 \. 0 [1-9]) $ "> <input type =" hidden "name =" code "value =" <? Php $ code = mt_rand (0, 100000); echo $ code;?> "> </Div> <div class =" input-group "> <span id =" available "> current balance: <? Php echo $ amount_available;?> Meta </span> </div> <button name = "confirm"> OK </button> </form> </div>

Process Form submission

If (isset ($ _ POST ['Confirm']) {// solve the problem of repeated calls twice if ($ _ POST ['code'] ==$ _ SESSION ['code']) {exit ;} else {$ _ SESSION ['code'] = $ _ POST ['code'];} // continue ....}

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.