The disabled form element is not submitted

徘徊边缘 提交于 2020-01-01 08:53:19

问题


I needed to show some preexisting data from a table and but needed to disable them to prevent user from editing them. So i disabled them

$form -> getElement("elementname") -> setAttrib("disable", true);

When I submit the form, I found out, that the form element does not get submitted at all, just because it was disabled. I confirmed this when I tested removing the disable options.

What is happening? Am i doing something wrong? How to solve this?


回答1:


This is by design, disabled elements do not get submitted with the form.

What you are doing is actually a null practice, no matter what you do to that form in put it will be editable by the end user. You simply cannot trust form input - even hidden fields - to not be tampered with.

Your best bet is to just display the information to the user and load it again after the form has been submitted; at worst store it in a session.




回答2:


This worked like a charm for me. It prevents the element from being edited and will pass it through the post.

$this->username->setAttrib('readonly', 'true');



回答3:


I handle these type of scenarios using hidden elements. Add a hidden element with the same content that is there in your disabled element. When the form is posted, use the value from the hidden element.

But be cautious that the use can modify the value of the hidden element using Firebug or other tools before submitting the form. Always check the form values again before processing.



来源:https://stackoverflow.com/questions/7875547/the-disabled-form-element-is-not-submitted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!