This topic is locked

Read Only Fields

7/26/2011 6:04:08 AM
PHPRunner General questions
I
imthebest author

I need to make few fields on Add and Edit page as Read only, depending on user type (User Group) who is logged in.

Please suggest how can this be achieved?
Thanks in advance.

C
cgphp 7/26/2011

You can create aliases for the fields. Set up them as readonly on the edit page and then check user login and show/hide your fields or aliases in the "Edit page: Before display" event: http://www.asprunner.com/forums/topic/6196-how-to-hide-controls-on-addedit-pages/

I
imthebest author 7/27/2011

Thanks cgphp.
Can you please elaborate in more detail? If I understand correctly, if a field has been given alias, then only its alias can be used in Event script, not the original field name. In that case, how will be show/hide original field (that is editable) and alias (that can be made read only). Also, on Visual Editor, we see only fields with Alias names only (original named fields are not shown). Then how will we make Alias as read only and keep original named field as editable?
Sorry, if these are basic questions, but I have yet not used Alias in phprunner hence these are the queries.
Thanks for helping.

C
cgphp 7/27/2011



If I understand correctly, if a field has been given alias, then only its alias can be used in Event script, not the original field name.



You can use both in the events.



Also, on Visual Editor, we see only fields with Alias names only (original named fields are not shown). Then how will we make Alias as read only and keep original named field as editable?



Be sure to check original field and alias field in the Fields section. Enable original fields for List page and Add/edit pages. Enable alias field only for add/edit pages.



Then how will we make Alias as read only and keep original named field as editable?



In the "Before display" event of add/edit pages:

global $conn;
$rs = CustomQuery("select GroupID from ugmembers where UserName ='".$_SESSION["UserID"]."' LIMIT 1",$conn);

$data=db_fetch_array($rs);
if($data['GroupID'] == 2) //change the int according to your app

{

$xt->assign("originalfieldname_fieldblock",FALSE); // show only the alias

}

else

{

$xt->assign("aliasfieldname_fieldblock",FALSE); // show only the original

}