Drupal 7: Comment Homepage URL Prefix Fix

Table of Contents

EDIT: I now recommend use of the excellent Disqus forum instead of built-in Drupal. It automates and crowd-sources spam control, and has a host of other features.

As this frustrated user put it,

I want Drupal comments to work like every other blog’s comments. Who are writing their homepage URL can write “www.example.com,” or “https://www.example.com,” and they both work. Right now, Drupal throws an error if the URL doesn’t contain “https://.”

The solution he received, with some modifications, works–but he’s on Drupal 6. It’s not much of a change for Drupal 7, but useful to note in any case; hence this post. As for Drupal 8, hopefully the fix is in the works.

WARNING: this fix requires editing Drupal Core, something highly discouraged. Be sure to back up both the original and the fixed version of the file “comment.module”.

  1. Open and backup file drupal\_root/modules/comment/comment.module
  2. Find the “function comment\_form\\_validate”
  3. Edit the last portion of this function, which checks the comment homepage, as follows:

ORIGINAL comment.module

if ($form_state['values']['homepage'] && !valid_url($form_state['values']['homepage'], TRUE)) {
  form_set_error('homepage', t('The URL of your homepage is not valid. Remember that it must be fully qualified, i.e. of the form <code>https://example.com/directory</code>.'));
}

MODIFIED comment.module

// EDITED to allow modernized values to be added (https://toryanderson.com or toryanderson.com)
  if ($form_state['values']['homepage']) {
      if (strpos($form_state['values']['homepage'], "://") === FALSE) {
        $form_state['values']['homepage'] = "https://" . $form_state['values']['homepage'];
    }
      if (!valid_url($form_state['values']['homepage'], TRUE)) {
          form_set_error('homepage', t('The URL of your homepage is not valid. Remember that it must be fully qualified, i.e. of the form <code>https://example.com/directory</code>.'));
    }
  }

Be sure to get the bracket-count right at the end. Notice what we’ve done: we’ve split the original test for a present url and a valid url into two section; first test if it’s present and if it has :// in it; add https:// if necessary. THEN test if it’s valid.

Good luck; once again, be careful messing with core and be aware that core updates may over-ride this, so you may have to repeat the fix.

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist