On a Drupal site with Advanced forum and comments installed, when commenting a post on a forum, there is a Notice:

Notice: Undefined index: homepage in comment_form_validate() (line 2161 of ..../comment.module)

After some investigation, I figured out bug in function : comment_form_validate:

Instead of :

  if ($form_state['values']['mail'] && !valid_email_address($form_state['values']['mail'])) {
    form_set_error('mail', t('The e-mail address you specified is not valid.'));
  }
  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 http://example.com/directory.'));

There should be:


  if (( isset($form_state['values']['mail']) && !empty($form_state['values']['mail']) ) && !valid_email_address($form_state['values']['mail'])) {
    form_set_error('mail', t('The e-mail address you specified is not valid.'));
  }
  if (( isset($form_state['values']['homepage']) && !empty($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 http://example.com/directory.'));

I attach the patch that should provide fix for it.

Cheers

Marek

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mareksal’s picture

Issue summary: View changes
FileSize
957 bytes
mareksal’s picture

Status: Active » Needs review
mareksal’s picture

FileSize
1.02 KB

The previous patch had an another bug.

This one should solve all the problems.

Status: Needs review » Needs work

The last submitted patch, 3: commentValidateForm-2405901-3.patch, failed testing.

mareksal’s picture

FileSize
1.03 KB
mareksal’s picture

Status: Needs work » Needs review

The last submitted patch, 1: commentValidateForm-2405901-2.patch, failed testing.

mareksal’s picture

Issue summary: View changes
MariskaTh’s picture

The patch in #5 worked for me.

Thanks!
Mariska.

nicrodgers’s picture

Status: Needs review » Needs work
+++ b/modules/comment/comment.module
@@ -2155,10 +2155,10 @@ function comment_form_validate($form, &$form_state) {
+  if ( ( isset($form_state['values']['mail']) && !empty($form_state['values']['mail']) ) && !valid_email_address($form_state['values']['mail'])) {
...
+  if ( ( isset($form_state['values']['homepage']) && !empty($form_state['values']['homepage']) ) && !valid_url($form_state['values']['homepage'], TRUE)) {

From the PHP manual page: A variable is considered empty if it does not exist or if its value equals FALSE.

So to avoid duplication and make the code easier to read, I'd suggest removing the isset() checks and just have the !empty().