I have not checked other new fields for same situation. I will do and report back

CommentFileSizeAuthor
#6 form_required.patch778 bytesChrisKennedy

Comments

vm’s picture

all other types of fields work as expected.

For now my workaround is to just add the red asterisk using HTML in the description field.

jpsalter’s picture

I've got the same problem. I can't seem to find out why - even after trudging through the code.

jpsalter’s picture

The theme_form_element function does not add the red * if there is no title. You can add the logic for this by adding some code:

theme_form_element is found in the includes/theme.inc file:

Modified function:

function theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {

  $output  = '<div class="form-item">'."\n";
  $required = $required ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';

  if ($title) {
    if ($id) {
      $output .= ' <label for="'. form_clean_id($id) .'">'. t('%title: %required', array('%title' => $title, '%required' => $required)) . "</label>\n";
    }
    else {
      $output .= ' <label>'. t('%title: %required', array('%title' => $title, '%required' => $required)) . "</label>\n";
    }
  }
  else {
    if ($id) {
      $output .= ' <label for="'. form_clean_id($id) .'">'. t('%required', array('%required' => $required)) . "</label>\n";
    }
    else {
      $output .= ' <label>'. t('%required', array('%required' => $required)) . "</label>\n";
    }
  }
  
  $output .= " $value\n";

  if ($description) {
    $output .= ' <div class="description">'. $description ."</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}
jpsalter’s picture

This function is a little more clean - the label is only added if the form is required:

function theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {

  $output  = '<div class="form-item">'."\n";
  $required = $required ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';

  if ($title) {
    if ($id) {
      $output .= ' <label for="'. form_clean_id($id) .'">'. t('%title: %required', array('%title' => $title, '%required' => $required)) . "</label>\n";
    }
    else {
      $output .= ' <label>'. t('%title: %required', array('%title' => $title, '%required' => $required)) . "</label>\n";
    }
  }
  //  addition to add red * for forms without title and required fields
  elseif ($required) {
    if ($id) {
      $output .= ' <label for="'. form_clean_id($id) .'">'. t('%required', array('%required' => $required)) . "</label>\n";
    }
    else {
      $output .= ' <label>'. t('%required', array('%required' => $required)) . "</label>\n";
    }
  }
  
  $output .= " $value\n";

  if ($description) {
    $output .= ' <div class="description">'. $description ."</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}
vm’s picture

Sweet! thanks for the followup. I will certainly employ this however, you might want to consider an actual patch file, so that this may get into core. I'm not sure how much attention this will get without being in patch form.

Again, Thank you very much.

ChrisKennedy’s picture

Title: when marking a new checkbox profile field as required no red asterisk shows » Display required asterisk even if there is no title
Version: 4.7.6 » 6.x-dev
Status: Active » Needs review
StatusFileSize
new778 bytes

Here is a patch for D6.

catch’s picture

Status: Needs review » Closed (duplicate)