On my Drupal 7 instance I am letting anonymous users "edit own webform content" or "access own webform results." The thing is, I want one or two of the fields to become un-editable after the initial submission. Once they click through the link in their confirmation email to edit their submission, I want the email and company name fields to be greyed out but all other fields to be editable. What is my path of least resistance?
2 Answers
From Programmatically modifying a webform with hook_form_alter():
function mymodule_form_alter( &$form, &$form_state,$form_id ){
global $user;
if (!$user->uid && $form_id == 'MY_WEBFORM_ID') {
$form['submitted']['MY_FORM_COMPONENT']['#disabled'] = TRUE;
}
}
I solved this by attaching some javascript to my module...
$form['#attached']['js'][] = array(
'data' => drupal_get_path('module', 'my_module') . '/my_javascript.js',
'type' => 'file',
);
Then, within that attached javascript file, I used...
document.getElementById("edit-submitted-name-of-organisation").disabled = true;
The reason why I couldn't do it in the hook_form_alter is because it was somehow preventing those fields from being editable from the beginning, even prior to the initial submission.