Mawg Mawg - 9 days ago 5
HTML Question

How can I make an entire HTML form "readonly" ? Server side only, please

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 3.5 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.

Answer

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

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