[2.6.x] Empty checkbox values not saved in configuration

Please report bugs here!

Moderator: Thorsten

Post Reply
oldperl
Posts: 37
Joined: Sat Oct 28, 2006 3:03 pm
Location: Franken
Contact:

[2.6.x] Empty checkbox values not saved in configuration

Post by oldperl »

Hi,

there is a bug, still existing in 2.6.1, saving changes in configuration.
If u want to uncheck any checked checkbox in configarea and save it, it will still shown as checked. This is caused by a not working hack in file admin/configuration.php (line 54 ff)

Code: Select all

// Hacks
    if (is_array($editData['edit'])) {
        foreach ($newConfigValues as $key => $value) {
            // Fix checkbox values: they are not returned as HTTP POST values...
            if (!array_key_exists($key, $editData['edit'])) {
                $newConfigValues[$key] = 'false';
            }
        }
    }

    $faqconfig->update($newConfigValues);
I cleared this up by coding a "dirty" fix for that, using another array for missing key. I believe that was intended to be done by the hack somebody wrote before.
Here's the fix, just replace the old code with the new one.

Code: Select all

// new empty checkbox hack by Ortwin Pinke <www.dceonline.de>
    $editData['neededCheckboxes'] = array(  'main.languageDetection',
                                            'main.disableAttachments',
                                            'main.enableAdminLog',                                            
                                            'main.ipCheck',
                                            'main.ldapSupport',
                                            'main.enableRewriteRules',
                                            'main.enableUserTracking',
                                            'main.enableWysiwygEditor',
                                            'main.enableUpdate',
                                            'main.useSslForLogins',
                                            'main.enableAttachmentEncryption',
                                            'main.optionalMailAddress',
                                            'main.useAjaxSearchOnStartpage',
                                            'records.enableVisibilityQuestions',
                                            'records.defaultActivation',
                                            'records.defaultAllowComments',
                                            'spam.checkBannedWords',
                                            'spam.enableCaptchaCode',
                                            'spam.enableSafeEmail'
                                        );

    foreach($editData['neededCheckboxes'] as $value) {
        if(!array_key_exists($value, $newConfigValues)) {
            $newConfigValues[$value] = "false";
        }
    }
    
    /*
    // you may remove this debugging stuff if not needed any more
    echo "<pre>";
    print_r($editData['edit']);
    print_r($newConfigValues);
    echo "</pre>";
    */
    $faqconfig->update($newConfigValues);
The only thing u have to do now while adding new checkboxes, u also have to add the checkbox name (key) in neededCheckboxes-array.
Maybe someone finds a better solution.
My first idea, reading fields out of db-conf-table, isn't useable cause of missing boolean type in db for needed checkboxfields.

Regards Ortwin
Man muss nicht alles wissen,
man muss nur wissen wo es steht

** FAQ CMS Contenido (powered by phpMyFAQ) ** - ** Forum CMS Contenido ** - ** DCEonline ** - ** DevBlog **
Thorsten
Posts: 15725
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: [2.6.x] Empty checkbox values not saved in configuration

Post by Thorsten »

Hi,

ich hab das eben gecheckt, da ist ein Problem. Ich arbeite an einem Fix.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Thorsten
Posts: 15725
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: [2.6.x] Empty checkbox values not saved in configuration

Post by Thorsten »

Hi,

hier ist mein Fix ohne Hack: http://github.com/thorsten/phpMyFAQ/com ... 6e5728faa1

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply