Newbie - Enable/Disable HTML input elements by login ID

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Fri Jul 18, 2003 7:19 pm

I am brand new to PHP and am looking for a way to enable/disable the input elements on a HTML form based on the login ID. Is there a function I can use that will disable any input for some users and enable it for others? Can I do this to the entire form and/or to specific elements? I have created the form in various parts so I can manipulate which parts different users have access to view.

Any direction or ideas are greatly appreciated.


User avatar
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Fri Jul 18, 2003 10:08 pm

The best way to do this is just to make the 'restricted' form elements just not show up. I believe that there is a JavaScript attribute called "disabled" that you can use to "grey out" a form field, but that's very easy to get around. The only way to really keep certain users from filling out certain form fields is just to make them not appear to those users. A simple conditional should do:

Code: Select all

if(user_is_authorized($username)) {
   echo '<input type="text" name="something">';
} else {
   /* show not-authorized message or just do nothing */


Sat Jul 19, 2003 5:29 am


Thanks for the suggestion, but I really need to show some portions of the form for other users but prevent them from editing some parts.

Basically I have a multipart form that the first user will start to fill out, submit to another user to approve, then go to another user to add addtional info and send to 3 other users for approval and comments. Other than the administrator, I want each user to be able to see previous input, but only edit their portion of the total form. Hope this makes some sense.

Thanks again,

User avatar
Joan Garnet
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Sat Jul 19, 2003 6:10 am

You can use the readonly attribute for example.

Or just print the other user's text as normal text and put only the editable part inside a textarea or whatever.
To keep every part (the parts with plain text from previous users) you can add the information into a database keeping track of which user has written it.

Just an idea :idea:


Sun Jul 20, 2003 8:14 am


Thanks for the tip and suggestion.


Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests