search

Home  >  Q&A  >  body text

python - 如何防止狂点提交表单按钮导致的数据重复?

高洛峰高洛峰2802 days ago1661

reply all(12)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:07:45

    Disable the button immediately after clicking it. If the submission fails, restore the button, otherwise it will be redirected to the success page.

    Or after clicking, a mask will pop up.

    However, both of the above solutions require js. Why don't you want to use js?

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:07:45

    1.JS button prevents repeated clicks

    2. Server cache control, the method is to write the library repeatedly

    3. Create a unique index in the database (for example, the post title is unique and cannot be repeated)

    reply
    0
  • 阿神

    阿神2017-04-18 10:07:45

    Can be controlled from the front and backend:

    • Add front-end control logic, when the user clicks to post, disable the "Post" button

    • Add background control logic. When a post request is sent, check whether the person has sent a post with the same title and content. If so, prohibit the creation of this duplicate post

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:07:45

    You can generate an id when rendering the template, then submit the id together when submitting, and then compare it with the backend, so that if the passed id is incorrect, then the processing will be ignored.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:07:45

    First, a simpler solution is to use the debounce function to limit the frequency of DOM callback triggers.

    Second, if you still have to consider the situation where users disable js in this era, then don’t do it on the front end.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:07:45

    This problem cannot be solved by relying on the front end alone.

    1. Add caching, use map for single machine, and use redis for distributed caching.

    2. Use Mysql’s stored procedure to hand over the concurrency pressure to the database

    3. Add lock, optimistic lock or pessimistic lock

    4. Unique key

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:07:45

    The current page generates a unique id. When submitting, the server determines that it will only be processed once, such as laravel的表单提交页都有个csrf_token

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:07:45

    Then write one yourself in the backgroundcsrfOkay, let me give you some ideas, automatically generate a key, and bring the key when submitting the content. If they are the same, reset the key or clear it. If they are different, it is submitted again.

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:07:45

    Form form post past a random string from a hidden field and put it into the session
    The program receives this random string and compares it with the string in the session. If it is the same, it will be submitted. If it is not the same, it will prompt an error. It needs to be reset when comparing. This session is enough

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:07:45

    1.JS verification, disable the submit button after submission
    2. Server-side verification, every time the page is refreshed, a token will be generated in the page. When submitting data to the server, it will be judged whether the token is valid, then the data will be processed and the token will be destroyed. If the front-end repeats The submission will definitely not be processed because the token has been destroyed

    reply
    0
  • Cancelreply