Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#5 | commentValidateForm-2405901-4.patch | 1.03 KB | mareksal |
Comments
Comment #1
mareksal CreditAttribution: mareksal commentedComment #2
mareksal CreditAttribution: mareksal commentedComment #3
mareksal CreditAttribution: mareksal commentedThe previous patch had an another bug.
This one should solve all the problems.
Comment #5
mareksal CreditAttribution: mareksal commentedComment #6
mareksal CreditAttribution: mareksal commentedComment #8
mareksal CreditAttribution: mareksal commentedComment #9
MariskaTh CreditAttribution: MariskaTh commentedThe patch in #5 worked for me.
Thanks!
Mariska.
Comment #10
nicrodgersFrom 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().