I am trying to find out how to modify a text input for one field of a quiz so that I can disable spellcheck.

Can I create a .tpl.php and add it to my theme folder to override it?

At the moment, it looks like the following:

<input autocomplete="off" type="text" id="edit-question-832-answer" name="question[832][answer]" value="" size="60" maxlength="256" class="form-text">

I simply with to add the following attributes to just that one field.

<input autocomplete="off" autocorrect="off" autocapitalize="off"  spellcheck="false"/>

I have looked inside modules/field/theme/field.tpl.php but do not see a way to modify the way text input fields are handled.

Which file am I supposed to edit to make this happen for a specific field?

Thank you.

4 Answers 4


Do not edit any files for this. Use hook_form_alter in a custom module to target this form and that form input and change its attribute.

See: https://stackoverflow.com/questions/9194821/alter-and-set-a-id-attribute-for-a-field-in-drupal-7


Inspect your form and find out what is your form_id

and put this code in your template.php file in your theme directory

function YOURTHEME_NAME_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == 'YOUR_FORM_ID') {
      // Merge new attributes with existing ones.
      $form['YOUR_FIED_MACHINE_NAME']['#attributes'] += array(
        'autocorrect' => 'off',
        'autocapitalize' => 'off',
        'spellcheck' => 'false',


if you have custom module you can also use HOOK_form_alter there
another solution is override your field.
How to override a field in drupal 7.

as example copy modules/field/theme/field.tpl.php to sites/all/themes/YOUR_THEME_NAME/templates/YOUR_FIELD_MACHINE_NAME--YOURCONTENTTYPE.tpl.php add your markup to it and clear the cache.

  • You shouldn't modify the attributes of a field in this way because if '#attributes' already have some information you are removing it and replace it with your new attributes. You should at least merge your new attributes array with the previous one; or simply add the new attributes 1 by 1... just like the answer by @juankvillegas below (¬¬) :D. Oct 14, 2016 at 14:51

If you can write your own module, you can implement the hook_form_alter:

function my_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'the_form_i_want_to_change') {
    $form['the_field']['#attributes']['autocorrect'] = 'off';
    $form['the_field']['#attributes']['autocapitalize'] = 'off';
    $form['the_field']['#attributes']['spellcheck'] = 'false';

You could start by making more 'visible' to yourself which field is rendered by which tpl.php. One way of doing this is by following the following.

  1. First add the line $conf['theme_debug'] = TRUE;to your settings.php file (you can find this e.g. in sites/default/settings.php or sites/yoursitename/settings.php
  2. Clear your cache
  3. Now visit the page where your field is displayed and look at the source code of the page. You will see, in html comments, the tpl.php files used for rendering this field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.