How to save an uploaded image in an admin form? I wrote the following module to upload a background image. My problem is, that my submit function is not called, though the pic is uploaded and showed in the block until the next cleanup is coming.The managed file table shows status 0...what should be 1 as far as i know.

Here is the Code of my Module: Whats the mistake?

function backgroundimage_block_info() {
    // This example comes from node.module.
    $blocks['backgroundimage'] = array(
        'info' =&gt; t('Background Image'),
    );


    return $blocks;
}
function backgroundimage_block_view($delta = '') {
    $fid_now=variable_get('backgroundimage');
    dpm($fid_now);
    $file_obj = file_load($fid_now);

    $bg_img_url = file_create_url($file_obj-&gt;uri);

    // This example is adapted from node.module.
    $block = array();

    switch ($delta) {
        case 'backgroundimage':
            $block['subject'] ="imagebackgroundblock";
            $block['content'] ="&lt;div class='background-image'&gt;&lt;img src='".$bg_img_url."'&gt;&lt;/div&gt;";

            break;


    }
    return $block;
}
function backgroundimage_admin() {
    $form = array();

    $form['backgroundimage'] = array(
        '#type' =&gt; 'managed_file',
        '#name' =&gt; 'backgroundimage_image',
        '#title' =&gt; t('upload image, huh!'),
        '#default_value' =&gt; variable_get('backgroundimage', ''),
        '#description' =&gt; t("Here you can upload an image to the background!"),
        '#required' =&gt; TRUE,
        '#upload_location' =&gt; 'public://backgroundimage/'
    );

    return system_settings_form($form);
}
function backgroundimage_form_submit($form, $form_state) {
    dpm("yeah"); // is not being called!
    $form['backgroundimage']['#file']-&gt;status = FILE_STATUS_PERMANENT;
    file_save($form['backgroundimage']['#file']);
}

function backgroundimage_menu() {

    $items = array();

    $items['admin/settings/backgroundimage'] = array(
        'title' =&gt; 'Settings Background Image',
        'description' =&gt; 'Image upload',
        'page callback' =&gt; 'drupal_get_form',
        'page arguments' =&gt; array('backgroundimage_admin'),
        'access arguments' =&gt; array('administer backgroundimage settings'),
        'type' =&gt; MENU_NORMAL_ITEM,
    );

    return $items;
}

?&gt; 


Thanks a lot!
You have used system_settings_form_submit() so you can add custom submit handler for your form by adding this code to your hook_menu

function backgroundimage_admin() {
    $form = array();

    $form['backgroundimage'] = array(
        '#type' =&gt; 'managed_file',
        '#name' =&gt; 'backgroundimage_image',
        '#title' =&gt; t('upload image, huh!'),
        '#default_value' =&gt; variable_get('backgroundimage', ''),
        '#description' =&gt; t("Here you can upload an image to the background!"),
        '#required' =&gt; TRUE,
        '#upload_location' =&gt; 'public://backgroundimage/'
    );
    $form['#submit'][] = 'backgroundimage_form_submit';
    return system_settings_form($form);

}