This topic is locked

read-only edit

9/13/2006 6:35:55 PM
PHPRunner General questions
J
Jean author

Hello,

I tried many combinations during hours,in vain. Can anyone tell me how in the _edit.php module (and perhaps in the _add.php too), I can make some field to become read-only when the group is not Admin.

I obtain some result with this code :
--------------------------

if ($_SESSION["AccessLevel"] == "Admin"){

// is field editable

if(GetEditFormat('OIP') != EDIT_FORMAT_HIDDEN){ echo "\r\n<tr><td class=shade>".Label("OIP")." </td><td>";}

echo BuildEditControl("OIP",$value,GetEditFormat("OIP"),MODE_EDIT);
if(GetEditFormat("OIP")==EDIT_FORMAT_READONLY OR $_SESSION['AccessLevel'] !== 'Admin')

{

if(Format("OIP")!=FORMAT_HTML && Format("OIP")!=FORMAT_FILE_IMAGE && Format("OIP")!=FORMAT_FILE && Format("OIP")!=FORMAT_HYPERLINK && Format("OIP")!=FORMAT_EMAILHYPERLINK && Format("OIP")!=FORMAT_CHECKBOX)

echo htmlspecialchars(GetData($rs,$data,"OIP", Format("OIP")));

else

echo GetData($rs,$data,"OIP", Format("OIP"));

}

echo GetLegendIcon("OIP");

if(GetEditFormat("OIP") != EDIT_FORMAT_HIDDEN)

{echo "</td></tr>";}

}

------------------------
...but the field becomes hidden not read-only AND the value of the hidden field becomes NULL. Pff...
Thanx for any help.
Jean

D
drh 9/14/2006

Jean,
I had to make some fields read only in the edit screen based on the value of one field in the record. This is how I did it. you will have to make some mods to my example, but maybe it will give you a boost in the right direction.
First I created a custom javascript program in the ./include directory. Lets call it custom_js.php. Mine looks like this. BTW, the value## comes from bringing up your page in a browser and then viewing the page source. Down towards the bottom you will see your fieldnames listed along with the value number. (Sorry if you already knew this.)
<script type="text/javascript">

if ((document.editform.value27.value) != 'N') // MY CONDITIONAL STATMENT

{

color = "#F1F1F1"; // used later down for distinquishing readonly fields
// make the following fields readonly

document.editform.value2.disabled = 1;

document.editform.value3.disabled = 1;

document.editform.value4.disabled =1;

document.editform.value5.disabled =1;

document.editform.value6.disabled =1;

document.editform.value7.disabled = 1;

document.editform.value8.disabled =1;

document.editform.value9.disabled = 1;

document.editform.value10.disabled =1;

document.editform.value11.disabled =1;

document.editform.value12.disabled =1;

document.editform.value13.disabled =1;

document.editform.value14.disabled =1;

document.editform.value15.disabled =1;

document.editform.value16.disabled =1;

document.editform.value17.disabled =1;

document.editform.value18.disabled =1;

document.editform.value19.disabled =1;

document.editform.value20.disabled = 1;

document.editform.value21.disabled = 1;

document.editform.value23.disabled = 1;

document.editform.value24.disabled = 1;
// shade fields so readonly fields look different from editable fields

document.editform.value2.style.background = color;

document.editform.value3.style.background = color;

document.editform.value4.style.background = color;

document.editform.value5.style.background = color;

document.editform.value6.style.background = color;

document.editform.value7.style.background = color;

document.editform.value8.style.background = color;

document.editform.value9.style.background = color;

document.editform.value10.style.background = color;

document.editform.value11.style.background = color;

document.editform.value12.style.background = color;

document.editform.value13.style.background = color;

document.editform.value14.style.background = color;

document.editform.value15.style.background = color;

document.editform.value16.style.background = color;

document.editform.value17.style.background = color;

document.editform.value18.style.background = color;

document.editform.value19.style.background = color;

document.editform.value20.style.background = color;

document.editform.value21.style.background = color;

document.editform.value23.style.background = color;

document.editform.value24.style.background = color;

document.editform.value22.focus();

}

else

{

document.editform.value2.readOnly = 0;

document.editform.value3.readOnly = 0;

document.editform.value4.readOnly = 0;

document.editform.value5.readOnly = 0;

document.editform.value6.readOnly = 0;

document.editform.value8.readOnly = 0;

document.editform.value9.readOnly = 0;

document.editform.value10.readOnly = 0;

document.editform.value11.readOnly = 0;

document.editform.value12.readOnly = 0;

document.editform.value13.readOnly = 0;

document.editform.value14.readOnly = 0;

document.editform.value15.readOnly = 0;

document.editform.value16.readOnly = 0;

document.editform.value17.readOnly = 0;

document.editform.value18.readOnly = 0;

document.editform.value19.readOnly = 0;

document.editform.value20.readOnly = 0;

document.editform.value21.readOnly = 0;

document.editform.value23.readOnly = 0;

document.editform.value24.readOnly = 0;

}
// have to enable the fields before writing to the db or they will be blank

function submitform()

{

document.editform.value2.disabled = '';

document.editform.value3.disabled = '';

document.editform.value4.disabled = '';

document.editform.value5.disabled = '';

document.editform.value6.disabled = '';

document.editform.value7.disabled = '';

document.editform.value8.disabled = '';

document.editform.value9.disabled = '';

document.editform.value10.disabled = '';

document.editform.value11.disabled = '';

document.editform.value12.disabled = '';

document.editform.value13.disabled = '';

document.editform.value14.disabled = '';

document.editform.value15.disabled = '';

document.editform.value16.disabled = '';

document.editform.value17.disabled = '';

document.editform.value18.disabled = '';

document.editform.value19.disabled = '';

document.editform.value20.disabled = '';

document.editform.value21.disabled = '';

document.editform.value23.disabled = '';

document.editform.value24.disabled = '';

document.editform.submit();

}
</script>
Now in your .._edit.php program find this line its under BUTTONS

<input class=button type=submit value="Save" id=submit1 name=submit1>

and replace with this

<input class=button type=submit value="Save" onclick="java script: submitform()">
then find this line towards the bottom:

if(file_exists("include/superbottom.php"))
add the next two lines directly above it.

if(file_exists("include/custom_js.php"))

include("include/custom_js.php");
Hope that helps some.
Dave

J
Jean author 9/16/2006

Hope that helps some.

Dave


Thank you very much, Dave ! I will try it this w-e.