I have an textfield and when there is a value in that field and in edit mode, I need to disable it because a few other people will be using the same webform and the client doesn't want other people to edit the data.
I tried JQuery and that created its own problems.
So I figured that I could do this:
$form['submitted']['participants_1']['first_name_1']['#webform_component']['extra']['disabled']=1;
Then print drupal_render($form['submitted']['participants_1']['first_name_1']);
But the textfield is still editable.
What am I missing here?
Comments
Comment #1
quicksketchYou're going too far into the array:
$form['submitted']['participants_1']['first_name_1']['#disabled'] = TRUE;
However such a change will make it so that the browser will not submit that field, effectively erasing the contents when the submission is saved. I'd suggest using #readonly instead, but either solution is not actually secure since users can easily re-enable the field with Firebug.
Comment #2
gwlangie commentedThe result of disabling the field was deleting the contents of the field. That explains why jquery didn't work either.
I understand the firebug issue. I won't be dealing with people with that much computer experience so I'm not worried about people using something like firebug and enabling the field.
Thanks Quicksketch.
Comment #3
quicksketchComment #4
gwlangie commentedJust to follow up. Setting the field to #readonly didn't work but you did send me in the right direction. Using JQuery, I set the field to readonly and that solved my problem.
$form['submitted']['participants_1']['first_name_1']['#readonly'] = TRUE;
and this did:
$('#edit-submitted-participants-1-first-name-1').attr('readOnly', true);
thanks for the help
Comment #5
quicksketch