tags:

views:

114

answers:

5

Edit again:

Surely this is standard stuff? I can't be reinventing the wheel??!! User fills in a form & 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, http://stackoverflow.com/questions/3503397/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 PGP.

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.

+3  A: 

There's no fully compliant, official HTML way to do it, but a little javascript can go a long way. Another problem you'll run into is that disabled fields don't show up in the POST data

Michael Clerx
If you've already validated the data you need to save it server side anyway. Sending it back and forth to the client is a big ol' security hole. Even if you use css, js or html to freeze the fields you can edit 'm with firebug or by manually changing the next HTTP request
Michael Clerx
+1 Thanks, but I can't use client side side solutions, see updated question (sorry, my bad)
Mawg
+3  A: 

There is no built in way that I know of to do this so you will need to come up with a custom solution depending on how complicated your form is. You should read this post:

Convert HTML forms to read-only

EDIT: Based on your update, why are you so worried about having it read only? You can do it via client-side but if not you will have to add the required tag to each control or convert the data and display it as raw text with no controls. If you are trying to make it read only so that the next post will be unmodified then you have a problem because anyone can mess with the post to produce whatever they want so when you do in fact finally receive the data you better be checking it again to make sure it is valid.

Kelsey
+1 Thanks, but I can't use client side side solutions, see updated question (sorry, my bad)
Mawg
"Based on your update, why are you so worried about having it read only? You can do it via client-side" Sorry, but 1) I can't do it client side (not my choice) and 2) if it looks to the user like he is changing things that might confuse him.
Mawg
@mawg well if it is purely for visuals then, the only thing I can recommend is replace all the controls inline with their text equivalent or adding the readonly property to the controls. There is no silver bullet and I get a sense that is what you are looking for. Can you post a snippet of the code that you are allowed to modify? It would help to just get a basis for what you are working with.
Kelsey
Mawg
+2  A: 

You can use this function to disable the form:

function disableForm(formID){
  $('#' + formID).children(':input').attr('disabled', 'disabled');
}

See the working demo here

Note that it uses jQuery.

Sarfraz
+1 Thanks, but I can't use client side side solutions, see updated question (sorry, my bad)
Mawg
+1  A: 

Have all the form id's numbered and run a for loop in JS.

 for(id = 0; id<NUM_ELEMENTS; id++)
   document.getElementById(id).disabled = false; 
Tommy
+1 Thanks, but I can't use client side side solutions, see updated question (sorry, my bad)
Mawg
+2  A: 

On the confirmation page, don't put the content in editable controls, just write them to the page.

Doobi
This really is the sanest approach. Don't present an uneditable form to a user, or you'll end up being an entry in the "Least Astonishment" question.
kibibu
And have a link to an edit page.
Peter Coulton
how? How can I display a checkbox and its check/not-checked condition, or a radio group with its selected item, etc?
Mawg