Currently, in my Drupal site, when an anonymous user enters a comment, there are three fields where the user can input text. These are author, subject, and comment. The only input that is required for submission is the comment text box, but I want to make it so that the author text box is required as well. I have tried using the methods here using the 'system.api.php' file within the system module and I have also tried changing the template.php file within /templates/corporateclean/. When I tried the systems module solution, nothing happened. In the template.php file I tried using the hook_form_FORM_ID_alter function, yet I was met with the blank screen. Here is my code that went inside both the system.api.php and template.php file:

function corporateclean_form_comment_note_forum_form_alter(&$form, &$form_state, $form_id) {
     $form['comment_node_forum_form'] = array(
     '#required' => TRUE;
     );
}

*Note: This code was never active in both files at the same time. It was always active in either one file or the other.
I've tried to find where the inputs in the comment field are defined so I could change the definition, but I cannot find the file where they are defined.
Does anyone have any ideas about how to make this work?

Comments

nevets’s picture

When I am unsure of the form id I start with implement hook_form_alter(), something like

function corporateclean_form_form_alter(&$form, &$form_state, $form_id) {
  drupal_set_message('Form id is ' . $form_id);
}

Now visit the page with the form. Note you may need to clear cache for the function to be recognized.
Once you know the form Id you can use that to implement a form specific version of the function.

When I do not know the form field name, I use something like

drupal_set_message("Form:<pre>" . print_r($form, TRUE) . '</pre>');

in the function then visit the form.

You will once you know the field name want code like

$form['your field name']['#required'] = TRUE;

Side note, *api.php are not actual part of Drupal, they document the apis for the particular module.

theredcameron’s picture

Thanks! The form will now not allow me to make a submission without filling in the name and comment field, just as I wanted.