diff -Naur mantisbt-1.2.3/bug_report.php mantisbt-patch/bug_report.php --- mantisbt-1.2.3/bug_report.php 2010-09-27 16:11:01.000000000 +0200 +++ mantisbt-patch/bug_report.php 2010-09-27 16:09:38.000000000 +0200 @@ -104,18 +104,24 @@ $t_def = custom_field_get_definition( $t_id ); # Produce an error if the field is required but wasn't posted - if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) && - ( $t_def['require_report'] || - $t_def['type'] == CUSTOM_FIELD_TYPE_ENUM || - $t_def['type'] == CUSTOM_FIELD_TYPE_LIST || - $t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST || - $t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) { + if ( $t_def['require_report'] + && $t_def['type'] != CUSTOM_FIELD_TYPE_CHECKBOX + && !gpc_isset_custom_field($t_id, $t_def['type']) + ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_EMPTY_FIELD, ERROR ); } - if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) { - error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); - trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); + if(gpc_isset_custom_field($t_id, $t_def['type'])) { + $t_custom_field_value = gpc_get_custom_field("custom_field_$t_id", $t_def['type'], NULL); + if ( $t_def['display_report'] + && !custom_field_validate( + $t_id, + $t_custom_field_value + ) + ) { + error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); + trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); + } } } @@ -135,13 +141,21 @@ # Handle custom field submission foreach( $t_related_custom_field_ids as $t_id ) { + $t_def = custom_field_get_definition( $t_id ); # Do not set custom field value if user has no write access. - if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) { + if ( !$t_def['display_report'] + || !custom_field_has_write_access( $t_id, $t_bug_id ) + ) { continue; } - $t_def = custom_field_get_definition( $t_id ); - if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) { + $t_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], ''); + if ( empty($t_custom_field_value) + && !$t_def['require_report'] + ) { + continue; + } + if(!custom_field_set_value($t_id, $t_bug_id, $t_custom_field_value, false)) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); } diff -Naur mantisbt-1.2.3/bug_update.php mantisbt-patch/bug_update.php --- mantisbt-1.2.3/bug_update.php 2010-09-27 16:10:52.000000000 +0200 +++ mantisbt-patch/bug_update.php 2010-09-27 16:09:33.000000000 +0200 @@ -137,19 +137,19 @@ continue; } + $t_old_custom_field_value = custom_field_get_value( $t_id, $f_bug_id ); # Produce an error if the field is required but wasn't posted - if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) && - ( $t_def['require_' . $t_custom_status_label] || - $t_def['type'] == CUSTOM_FIELD_TYPE_ENUM || - $t_def['type'] == CUSTOM_FIELD_TYPE_LIST || - $t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST || - $t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) { - error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); - trigger_error( ERROR_EMPTY_FIELD, ERROR ); + if ( $t_def['require_' . $t_custom_status_label] + && $t_def['type'] != CUSTOM_FIELD_TYPE_CHECKBOX + && !gpc_isset_custom_field($t_id, $t_def['type']) + ) { + if(!isset($t_old_custom_field_value)) { + error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); + trigger_error( ERROR_EMPTY_FIELD, ERROR ); + } } $t_new_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ); - $t_old_custom_field_value = custom_field_get_value( $t_id, $f_bug_id ); # Don't update the custom field if the new value both matches the old value and is valid # This ensures that changes to custom field validation will force the update of old invalid custom field values diff -Naur mantisbt-1.2.3/core/custom_field_api.php mantisbt-patch/core/custom_field_api.php --- mantisbt-1.2.3/core/custom_field_api.php 2010-09-27 16:11:18.000000000 +0200 +++ mantisbt-patch/core/custom_field_api.php 2010-09-27 16:34:03.000000000 +0200 @@ -1172,12 +1172,11 @@ $t_valid &= ( $p_value == null ) || ( ( $p_value !== false ) && ( $p_value > 0 ) ); break; case CUSTOM_FIELD_TYPE_CHECKBOX: - # Checkbox fields can hold a null value (when no checkboxes are ticked) + case CUSTOM_FIELD_TYPE_MULTILIST: + # These fields can hold a null value (when no values are selected) if( $p_value === '' ) { break; } - # If checkbox field value is not null then we need to validate it... (note: no "break" statement here!) - case CUSTOM_FIELD_TYPE_MULTILIST: $t_values = explode( '|', $p_value ); $t_possible_values = custom_field_prepare_possible_values( $row['possible_values'] ); $t_possible_values = explode( '|', $t_possible_values );