Posted by earnie on March 23, 2009 at 1:17pm
6 followers
| Project: | Drupal core |
| Version: | 6.x-dev |
| Component: | forms system |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
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
#1
FYI, a wikitools issue already exists #262354: Can't save wiki content - title is locked and empty (Move Protection broken).
#2
Bumping to D7.
This is due to the fact that some value callbacks (
form_type_*_value()functions) returns a value even when$editis NULL (which is the case when a disabled element is posted).In the case at hand:
<?phpfunction 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.#3
#4
Thanks, Damien. What do you suggest for a fix? Maybe
<?phpfunction 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);
}
}
?>
#5
Maybe this is better?
<?phpfunction 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);
}
}
?>
#6
Actually, this is already fixed in Drupal 7.
Here is a test.
#7
Good!
#8
Excellent! Go, DamZ, GO! :)
Committed to HEAD.
#9
This is still a bug in Drupal 6.
#10
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.
#11
This one seems working for me in D6 and makes the value available after "submit", nevertheless the #disabled is TRUE:
<?php// 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...