4

Here is my form

{exp:safecracker
    channel="dummy"
    class="form-horizontal"
    dynamic_title="Place"
    error_handling="inline"
    include_jquery="no"
    return="test/place-form-done"
    safecracker_head="no"
}
    <fieldset>
        <legend>Place</legend>

        <div class="control-group">
            <div class="controls">
                <input type="text" name="place" value="" id="place" />
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>

    </fieldset>
{/exp:safecracker}

When I submit, I get this

A PHP Error was encountered
Severity: Notice
Message: Undefined index: checkbox_fields
Filename: libraries/safecracker_lib.php
Line Number: 1210

Any idea why this is happening?

6

This is a known bug in ExpressionEngine 2.5.3, see BugTracker. You need to be logged in to view.

The fix requires adjusting some code in the SafeCracker modules file. See below…

Open system/expressionengine/modules/safecracker/libraries/api/Api_sc_channel_entries.php and find this code on line 66:

$checkbox_fields = explode('|', $data['checkbox_fields']); 
And REPLACE it with:

$checkbox_fields = isset($data['checkbox_fields']) ? explode('|', $data['checkbox_fields']) : array(); 

This may have been patched in the EE 2.5.5 update, but I'm not certain. You can apply this fix manually.

I should also mention that for some people applying the fix caused another error to occur, see…

A PHP Error was encountered
Severity: Notice
Message: Undefined index: checkbox_fields
Filename: libraries/safecracker_lib.php
Line Number: 1210

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /system/codeigniter/system/core/Exceptions.php:170)
Filename: libraries/Functions.php
Line Number: 402

This was logged as a separate bug, with it's own fix. But if that error occurs for you, the fix is listed below.

Find this code starting at line 1210 in /system/expressionengine/modules/safecracker/libraries/safecracker_lib.php:

foreach (explode('|', $_POST['checkbox_fields']) as $checkbox)
{
    if ( ! isset($_POST[$checkbox]))
    {
        $_POST[$checkbox] = '';
    }
} 
Replace that block of code with this:

if (isset($_POST['checkbox_fields']))
{
    foreach (explode('|', $_POST['checkbox_fields']) as $checkbox)
    {
        if ( ! isset($_POST[$checkbox]))
        {
            $_POST[$checkbox] = '';
        }
    }
} 

Good luck.

4

This was patched in 2.5.4, according to the changelog.

1
  • I was going to mention upgrading, but didn't want to qualify the answer against what 3rd party add-ons he might be using that require postponing the upgrade. Dec 24 '12 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.