开发者

How can I make a textbox readonly/disable for users and not for the admin (PHP)?

开发者 https://www.devze.com 2023-02-18 02:46 出处:网络
I\'m trying this stuff but all I found is TinyMCE codes. Can you help me in here? I\'m creating a system with tables(input type=\"text\").. Where I can put my daily allowance for monday-friday\'s. I w

I'm trying this stuff but all I found is TinyMCE codes. Can you help me in here? I'm creating a system with tables(input type="text").. Where I can put my daily allowance for monday-friday's. I want that only me can put numbers on that textarea.. When other users logged in, the textar开发者_运维百科ea is disabled/not editable.. How can I start with the coding? I start studying php yesterday :)


Generally speaking, in this kind of case, you'll want to display input fields to your admin :

<input type="text" name="..." id="..." value="..." />

And you'll only display values to the other users -- no input fields, as they don't have to do any input.


I suppose you have some way of testing if a user is an admin, either using a database, or a session ?

If so, depending on the kind of user, you'll use an if statement, to either display the input, or the value :

// $isAdmin has to be set accordingly
if ($isAdmin) {
    echo '<input type="text" name="..." id="..." value="..." />';
} else {
    echo "the value";
}


After that, of course, on form's submission, you'll do the same test, to only work with $_POST if the form has been submitted by an admin.


I too like the idea pointed out by Pascal MARTIN and Phoenix....

But still if are looking for disabling the textbox or textarea we have two options for it...

1) disabled="disabled" add these option to the required textarea or text field

2) readonly="readonly"

where option 1 only allows user to view the content....

option 2 allows users to view the content as well as copy it ....but cannot modify it.................


Check to see if you are not logged in, and if so, add disabled="disabled" to the input and throw any POSTs that attempt to update data.


An easy way to hide the text area is with the black-overlay class. Create a div just below the text area and assign this. You may control the opacity and cursor as well as the area. Nothing is fool proof, but with min opacity, they will not know it is there. It is always possible to change the screen size to move the area if scrollable. but it works.

.textarea_overlay {
    display: block; 
    position: fixed; 
    margin-top: -??;    
    width: ??;  
    height: ??; 
    background-color: black; 
    z-index:1001;   
    -moz-opacity: 0.8;  
    opacity:.01; 
    filter: alpha(opacity=80);  
    cursor: not-allowed; 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号