What's the point of having hidden input in HTML? What are common uses for this?

后端 未结 12 1163
无人共我
无人共我 2020-12-01 14:51

I don\'t see the benefit of having hidden input? If you set the value of the hidden input why not just use that value at the point where you reference this hidden input?

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 15:00

    All answers explained why we using hidden inputs in form but here is the security concern.

    Security concern

    Using hidden inputs in forms can be tampered/changed by View source or using developer tools in any browser.

    Solution

    Use cryptography in your code/project to avoid changing values in hidden input by attackers/hackers.

    Generic Solution

    If you want to store any data in hidden input first encrypt the data and store them in hidden input. When form is submitted then decrypt them if values not change then save your data. If changed then show some error or else.

    Further reading

    Cryptography

    Wiki Cryptography


    For framework Developers

    Other framework developers can find cryptography in their framework.

    Cryptography in Laravel(PHP)

    Cryptography in .Net

    Cryptography in Django

提交回复
热议问题