Drupal Poll Module’s Annoying 128 Character Limit

Posted November 3rd @ 10:16 am  |  Filed in: Drupal    

I’m working on a project that is giving me some hardcore Drupal experience, and in general I’m liking Drupal quite a bit (more on this when the project is finished though).

Anyways, even though I’m working with Drupal 6, there seems to be some legacy code from older versions in place - among them the 128 character limit (which was imposed to support old version of MySQL). While the node database schema has been updated to a default of 255 characters for node titles, the poll schema appears to impose this old restriction to some degree.

The Solution

Fortunately, the solution is simple. Open up poll.module, look for the function called poll_form(), and add ‘#maxlength’ => 255 to the $form['title'] array:

$form['title'] = array(
   '#type' => 'textfield',
   '#title' => check_plain($type->title_label),
   '#required' => TRUE,
   '#default_value' => $node->title,
   '#weight' => -5,
   '#maxlength' => 255,
);

Reload your modules by simply visiting the modules page in the admin area, and you can now have poll questions up to 255 characters.

2 Comments

  1. » soulston said on January 21, 2010 at 15:24...

    Just in case anyone else finds this, the better approach would be to use hook_form_alter() rather than hacking core.

    something like:

    /**
    * Implementation of hook_form_alter().
    */
    function INSERT_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == ‘poll_node_form’) {
    $form['title']['#maxlength'] = ‘255′;
    }
    }

  2. http://www.stoptimestudio.com » Matt said on January 21, 2010 at 15:34...

    Thanks soulston! This was a solution I used before I learned how to write modules, and I have come to agree that hacking core sucks. Fortunately, it seems to have been remedied in later versions of Drupal, so this is probably no longer even needed, cheers.

Leave a comment

OpenID Login

Standard Login

Options:

Size

Colors