This topic is locked
[SOLVED]

 Disable Edit Field

1/25/2013 3:57:55 PM
PHPRunner General questions
R
rustler45 author

I have a field on the Edit page that I need to be read-only for all users except admin. I found a solution on the forum but cant seem to get it to work for mine. Here is what I found:
In the "Before display" event of the edit page, enter the following code:
if($values['group_field_name'] == 'user')

{

$attr = $xt->fetchVar("username_editcontrol");

$attr = str_replace(">"," READONLY=READONLY>",$attr);

$xt->assign("username_editcontrol",$attr);}

I have tried several ways using my information but I cant get it to work.
My field is "Status" and I have two groups:
The GroupID field in User Group Permissions is GID
users are:

admin = 1

users = 18
Can someone point me in the right direction please.
thanks,

Rusty

W
wildwally 1/25/2013

I wasn't aware that this could be done through PHP alone - not saying it can't I just was aware. The way that I went about making things read only was evaluating my criteria whether it was the status of something or the users access level in a PHP event like Process record values. The I would pass a variable to the javascript onload event using the $pageObject->setProxyValue, this can be found in the manual. And in the js onload event evaluate with a simple if condition true then make control read only with .makeReadonly();
Hope that helps, but if the other is possible I might look into that as it's a direct change and a little less coding.

Sergey Kornilov admin 1/25/2013

My suggestion is to use Javascript API makeReadonly() or setDisabled() functions.

http://xlinesoft.com/phprunner/docs/makereadonly.htm

http://xlinesoft.com/phprunner/docs/ctrl_setdisabled.htm
How to pass data from PHP to Javascript:

http://xlinesoft.com/phprunner/docs/how_to_access_php_variables.htm

R
rustler45 author 1/27/2013

Thanks for the responses but I need the Status field to be readonly for all users except admin users. I would like to make the code that Cristian wrote work for mine. I have used the orginal code he wrote and change it based on my inforamtion as below:
if($values['GroupID'] == '18')

{

$attr = $xt->fetchVar("Status_editcontrol");

$attr = str_replace(">"," READONLY=READONLY>",$attr);

$xt->assign("Status_editcontrol",$attr);
}
Can anyone see a mistake that I am making?
thanks!

R
rustler45 author 1/28/2013

I also tried it this way:
if($_SESSION['GroupID'] == '18')

{

$attr = $xt->fetchVar("Status_editcontrol");

$attr = str_replace(">"," READONLY=READONLY>",$attr);

$xt->assign("Status_editcontrol",$attr);
}
But it doesnt work either.

Sergey Kornilov admin 1/28/2013

You use incorrect approach to this task. Do not use hacks, use API designed specifically for this purpose.

R
rustler45 author 1/28/2013

Sergey,

I went to your links and studied those and finally after many tries using different values, I got it working. Thanks for the help!