I don't know if this exists in 7.x but it does in 6.10. However, I suspect that the issue hasn't changed between the two since I couldn't find any relative issue. I have installed the wikitools on a version 6.10 release and do not allow most users to change the title. Wikitools enables this by adding a #disabled to the title field in the node edit form which worked perfectly in version 5.3. However, in 6.10 and probably 7.x the value doesn't carry to the validation and the value becomes lost so the user sees a "Title field is required" error message. I will open a sister issue to wikitools as well to make sure their maintainers are aware.

Comments

Anonymous’s picture

damien tournoud’s picture

Version: 6.10 » 7.x-dev

Bumping to D7.

This is due to the fact that some value callbacks (form_type_*_value() functions) returns a value even when $edit is NULL (which is the case when a disabled element is posted).

In the case at hand:

function form_type_textfield_value($form, $edit = FALSE) {
  if ($edit !== FALSE) {
    // Equate $edit to the form value to ensure it's marked for
    // validation.
    return str_replace(array("\r", "\n"), '', $edit);
  }
}

Here str_replace() will cast the NULL $edit value to an empty string, leading to that bug.

damien tournoud’s picture

Title: Using FAPI #disabled on causes values to be ignored. » Using FAPI #disabled on some element types causes values to be ignored
Anonymous’s picture

Thanks, Damien. What do you suggest for a fix? Maybe

function form_type_textfield_value($form, $edit = FALSE) {
  if ($edit !== FALSE && $edit !== NULL) {
    // Equate $edit to the form value to ensure it's marked for
    // validation.
    return str_replace(array("\r", "\n"), '', $edit);
  }
}
Anonymous’s picture

Maybe this is better?

function form_type_textfield_value($form, $edit = NULL) {
  if ($edit !== NULL) {
    // Equate $edit to the form value to ensure it's marked for
    // validation.
    return str_replace(array("\r", "\n"), '', $edit);
  }
}
damien tournoud’s picture

Status: Active » Needs review
StatusFileSize
new4.93 KB

Actually, this is already fixed in Drupal 7.

Here is a test.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Good!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Excellent! Go, DamZ, GO! :)

Committed to HEAD.

damien tournoud’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Active

This is still a bug in Drupal 6.

gábor hojtsy’s picture

I think we had duplicates for this, so marking the tests for backport does not seem to make that much sense. I found #426056: Server-side enforcement of #disabled is inconsistent and #227966: Use default values to #disabled form fields with a quick search.

hass’s picture

This one seems working for me in D6 and makes the value available after "submit", nevertheless the #disabled is TRUE:

    // TODO: '#default_value' is currently broken with '#disabled', see #410926.
    $form['googleanalytics_custom_var']['slots'][$i]['slot'] = array(
      //'#attributes' => array('readonly' => 'readonly'),
      //'#default_value' => $i,
      '#description' => t('Slot number'),
      '#disabled' => TRUE,
      '#size' => 1,
      '#type' => 'textfield',
      '#value' => $i,
    );

As I'm not mister FAPI - I hope this code is correct and will not break after this bug may be fix here...

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.