views:

26

answers:

1

The user sees a form with many controls, including a list box. He selects a single item in the list box and presses "submit".

In PHP I access $_POST[] and want to display the list box as read-only or disabled with his his selected item also selected. It should be read-only or disabled because I am showing him what he submitted and I don't want him changing it.

Can someone please give a very simple code example? (it has to work in MS IE (not my choice))


Edit for clarification:

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.

I have a problem only with a listbox (size >1, not combobox). I want to display ll of the initial choices but the user should not be allowed to change the selection, i.e, display all items, with one selected as either readonly or disabled.

+1  A: 
<form action="" method='post'>
<?php 
$disabled = isset($_POST['list'])?"disabled='disabled'":"";
?>
<select name='list' <?php echo $disabled;?> >
  <?php $selected = isset($_POST['list'])&&$_POST['list']=="1"?"selected='selected'":"";?>
  <option value="1" <?php echo $selected;?>>option1</option>
  <?php $selected = isset($_POST['list'])&&$_POST['list']=="2"?"selected='selected'":"";?>
  <option value="2" <?php echo $selected;?>>option2</option>
</select>

<input type="submit" value="Submit" />
</form>

i know i know... it looks horrible, there are cleaner ways to do it. but it works as an example

pleasedontbelong
This does indeed work. The select is produced, visible and the selected items cannot be changed. The only downside of this is that when the form is submitted, the disabled inputs are not sent in the POST array. You could either populate additional hidden inputs detailing what was selected, or, have an onsubmit action on the form that enables the select before completing the submission...
Brendan Bullen
Am I missing the point? I don't the fields to be disabled on the input form. The user can edit them there. But when he submits it I want to show the same form readonly with a confirmation message.
Mawg