Error messages don't appear when creating/editing custom breadcrumbs

Vallenwood - September 18, 2007 - 21:29
Project:Custom Breadcrumbs
Version:5.x-1.2
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

On line 166, the custom_breadcrumbs_form_validate function appears, and it throws an error when you don't have the same number of entries in the "titles" box as the "paths" box. However, the code for form_set_error is incorrect, and so the error is never displayed; it simply refreshes the edit screen and no new breadcrumb (or edited breadcrumb) is created. form_set_error requires that the first argument be the actual form field the error relates to (so Drupal knows which one to outline in red).

Solution is in the attached patch. The manual version is to cut the function starting at line 166:

<?php
function custom_breadcrumbs_form_validate($form_id, $form_values) {
 
$path_count = count(explode("\n", $form_values['paths']));
 
$title_count = count(explode("\n", $form_values['titles']));
  if (
$title_count != $path_count) {
   
form_set_error(t('Every link path must have a matching title. There are !paths paths, and !titles titles.', array('!paths' => $path_count, '!titles' => $title_count)));
  }
}
?>

and replace it with:

<?php
function custom_breadcrumbs_form_validate($form_id, $form_values) {
 
$path_count = count(explode("\n", $form_values['paths']));
 
$title_count = count(explode("\n", $form_values['titles']));
  if (
$title_count != $path_count) {
   
$error_field = ($title_count > $path_count) ? 'paths' : 'titles';
   
form_set_error($error_field,t('Every link path must have a matching title. There are !paths paths, and !titles titles.', array('!paths' => $path_count, '!titles' => $title_count)));
  }
}
?>

Problem solved. As you can see, it decides which field to outline in red by deciding which of the two textareas has fewer lines entered. That one gets the "error" designation. Enjoy!

AttachmentSize
custom_breadcrumbs_error_message.patch892 bytes

#1

Jody Lynn - February 15, 2008 - 00:22
Status:needs review» reviewed & tested by the community

I got the same problem because I accidentally had a blank line at the end of one of the lists. As a result the form did nothing at all.

#2

NaX - August 13, 2008 - 07:15
Priority:normal» critical

I fixed this on one of my sites by adding a blank field. Because the form is so simple it really does not need to show the field that has the problem and because the two fields are related they should ether both be highlighted or nether should be highlighted.

I think this is a critical problem and needs to be fixed. If I did not know PHP I would not be able to use this module because I had no idea that there was a problem until I looked at the code.

<?php
form_set_error
('', t('Every link path must have a matching title. There are !paths paths, and !titles titles.', array('!paths' => $path_count, '!titles' => $title_count)));
?>

Ether fix should work; it does not really matter as long as the user sees an error message.

#3

MGN - August 15, 2009 - 02:08
Status:reviewed & tested by the community» fixed

Committed to 5.x-1.x-dev.

#4

System Message - August 29, 2009 - 02:10
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.