我怎样才能使整个HTML表单“只读” ?请仅服务器端 [英] How can I make an entire HTML form "readonly" ? Server side only, please

查看:123
本文介绍了我怎样才能使整个HTML表单“只读” ?请仅服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次编辑:



当然这是标准的东西?我不能重塑轮子?? !!用户填写表单并将其展示给他(使用PHP,但这不重要)。你把它展示给他确认,所以他不应该再试图改变它......




请参阅相关的问题,如何显示一个表单列表框为只读或禁用选定的索引?它的要点是,我想执行什么必须是一个非常普通的任务...



有两种形式 - HTML中的提交表单和处理&在第一种形式中提供了许多控件的选择,第二种形式验证输入,如果有效,再次用确认消息显示输入形式。在这第二种形式中,所有字段必须是静态的。



从我所看到的,一些表单控件可以是 readonly 所有可以是禁用,不同之处在于您仍然可以选择只读字段。

这个字段按字段是否有标记整个表单为只读/禁用/静态,使用户不能改变任何控制?






编辑:谢谢所有的JS解决方案(我有+1),但我仅限于服务器端解决方案。对不起,我原本应该这样说。






[更新]七年后仍然可以得到答案;-)我最后做的是从PHP生成表单,并为每个字段写入 readonly disabled 属性(根据控件类型而定),根据全局变量设置为true或false。 解决方案

整个表单的内容位于< fieldset> 标记中,并将其设置为禁用属性。

 < form> 
< fieldset已禁用>
< input />
< input />
< input />
< / fieldset>
< / form>


Edit again:

Surely this is standard stuff? I can't be reinventing the wheel??!! User fills in a form and you show it to him (using PHP, but that should not matter). You show it to him as confirmation, so he should not be able to attempt to change it again ...


See related question, How to display a form list box as read-only or disabled with a selected index? The gist of it is that I want to perform what must be a very common task ...

There are two forms - a submission form in HTML and a processing & acknowledgement form in PHP.

The first form offers a choice in many controls, the second verifies the input and, if valid, displays the input form again with a confirmation message. On this second form all fields must be static.

From what I can see, some form controls can be readonly and all can be disabled, the difference being that you can still tab to a readonly field.

Rather than doing this field by field is there anyway to mark the whole form as readonly/disabled/static such that the user can't alter any of the controls?


Edit: thanks for all the JS solutions (which I have +1) but I am restricted to a server-side solution. Sorry, I ought to have said this originally.


[Update] This is still getting answers seven years later ;-) What I did, in the end, was to generate the form from PHP and, for each field write a readonly or disabled attribute (as appropriate to the type of control), set to true or false according to to a global variable.

解决方案

Wrap the entire form's content in a <fieldset> tag and set it's disabled attribute.

<form>
    <fieldset disabled>
        <input/>
        <input/>
        <input/>
    </fieldset>
</form>

这篇关于我怎样才能使整个HTML表单“只读” ?请仅服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆