Hi, I'm trying to disable the e-mail and user_name filed in the User Account Edit page. These details will be populated from LDAP so an user should not be able to edit them. I've poked around and found the code which handles this in user.module. Now I need to disable this control. <Code> $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), NULL, TRUE); </Code> looking up documentation for the form_textfield control (http://drupaldocs.org/api/head/function/form_textfield) tells me that I need to pass HTML attributes to this in the form of an associative array. Now to disable it I need to pass the attribute 'readonly' so I created an associative array as such $html_params = array("RO" => "readonly") and passed it to form_textfield as such: <Code> $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), *$html_params*, TRUE); </Code> (The *'s highlight the change) However this does not seem to be working,E-mail field is still editable. What am I missing ? Please help. -Toufeeq -- blog @ http://toufeeq.blogspot.com
On 11 Dec 2005, at 3:49 PM, Toufeeq Hussain wrote:
Hi,
I'm trying to disable the e-mail and user_name filed in the User Account Edit page. These details will be populated from LDAP so an user should not be able to edit them.
This can be easily done using Drupal 4.7 : function mymodule_form_alter($form_id, $form) { if ($form_id == 'user_edit') { $form['account']['name']['#type'] => 'value'; $form['account']['email]['#type'] => 'value'; } return $form; } For 4.6 you will have to edit the module. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Hi, On 12/11/05, Adrian Rossouw <adrian@bryght.com> wrote:
On 11 Dec 2005, at 3:49 PM, Toufeeq Hussain wrote:
Hi,
I'm trying to disable the e-mail and user_name filed in the User Account Edit page. These details will be populated from LDAP so an user should not be able to edit them.
This can be easily done using Drupal 4.7 :
function mymodule_form_alter($form_id, $form) { if ($form_id == 'user_edit') { $form['account']['name']['#type'] => 'value'; $form['account']['email]['#type'] => 'value'; }
return $form; }
For 4.6 you will have to edit the module.
Adrian, Sadly I have to do this on Drupal 4.6 (4.6.3). - toufeeq -- blog @ http://toufeeq.blogspot.com
I'm trying to disable the e-mail and user_name filed in the User Account Edit page.
It's a 'disabled' attribute you want to set, http://www.w3.org/TR/REC-html40/interact/forms.html#adef-disabled Perhaps: $html_params = array("disabled" => "TRUE");
Nedjo Rogers wrote:
I'm trying to disable the e-mail and user_name filed in the User Account Edit page.
It's a 'disabled' attribute you want to set, http://www.w3.org/TR/REC-html40/interact/forms.html#adef-disabled
Perhaps:
$html_params = array("disabled" => "TRUE");
I tried w/: $html_params = array("disabled" => ""); BUT if it is disabled, at submitting, validation fails. (Missing value)
On Sun, December 11, 2005 2:27 pm, Keve said:
Nedjo Rogers wrote:
I'm trying to disable the e-mail and user_name filed in the User Account Edit page.
It's a 'disabled' attribute you want to set, http://www.w3.org/TR/REC-html40/interact/forms.html#adef-disabled
Perhaps:
$html_params = array("disabled" => "TRUE");
I tried w/: $html_params = array("disabled" => "");
BUT if it is disabled, at submitting, validation fails. (Missing value)
I had to do this recently for another client. What I ended up with was editing the edit form for users to show the normal textfield input if the user had admin users permission, and to print the value as text along with a hidden field that contains the same information. That way it still got passed back to the form handler, but it was still not user editable through normal means. Of course, while quick and easy it was also a security hole (save HTML, edit the hidden input field, resubmit), but it was an internal app so that was less of a concern. :-) I would recommend also putting the same if(user_access()) call in the form processing function. The total number of changes should be under 10 lines, once you find the right spots in the code. The 4.7 way does sound considerably cleaner. :-) --Larry Garfield
The correct form for readonly: $html_params = array("readonly" => "readonly") Keve. Toufeeq Hussain wrote:
Hi,
I'm trying to disable the e-mail and user_name filed in the User Account Edit page. These details will be populated from LDAP so an user should not be able to edit them.
I've poked around and found the code which handles this in user.module. Now I need to disable this control.
<Code> $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), NULL, TRUE); </Code>
looking up documentation for the form_textfield control (http://drupaldocs.org/api/head/function/form_textfield) tells me that I need to pass HTML attributes to this in the form of an associative array.
Now to disable it I need to pass the attribute 'readonly' so I created an associative array as such $html_params = array("RO" => "readonly") and passed it to form_textfield as such:
<Code> $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), *$html_params*, TRUE); </Code>
(The *'s highlight the change)
However this does not seem to be working,E-mail field is still editable. What am I missing ?
Please help. -Toufeeq -- blog @ http://toufeeq.blogspot.com
Hi Keve, On 12/12/05, Keve <kevex@pro.hu> wrote:
The correct form for readonly:
$html_params = array("readonly" => "readonly") This solution works like a charm.
Thanks. -Toufeeq -- blog @ http://toufeeq.blogspot.com
participants (5)
-
Adrian Rossouw -
Keve -
Larry Garfield -
Nedjo Rogers -
Toufeeq Hussain