Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user

I'd like to clear the managed file field each time the contents are sent off for further processing on submit. The

The callbacks work fine, but I have repeatedly come unstuck in my goal of having a "fresh" form everytime I need to submit a new image.

The form is defined thus:

function        mymodule_form($form, &$form_state) {

$form['Input type'] = array(
    '#type'=>'fieldset',
    '#title'=>'Upload your image'
);

$form['Input type']['file'] = array(
    //file left in non-permanent state for testing purposes
    '#type' => 'managed_file',
    '#title'=> t('Upload image'),
    '#description' => t('Choose an image to upload. Format must be gif, png, jpg, and may not exceed 2MB in size. Press Submit to confirm your selection.'),
    '#upload_validators' => array(
        'file_validate_extensions' > array('gif png jpg jpeg'),
        'file_validate_size'=>array(512*512*512),
    ),
    '#upload_location'=>'public://mymodule_uploads',
);
       
$form['Input type']['submit'] = array(
    '#type'=>'submit',
    '#value' =>t('Submit'),
    '#submit'=>array('mymodule_clear_image_submit'),
    '#ajax' => array(
            'callback'=> 'mymodule_update_image_callback',
            'wrapper'=>'somediv'
        ),
);
return $form;
}
function        mymodule_update_image_callback($form,&$form_state) {
$picture_settings = array( 
        'image' => file_create_url($form['Input type']['file']['#file']->uri)
        );
    drupal_add_js(array('mymodule' => $picture_settings),'setting');
 
    return;
}

function        mymodule_clear_image_submit($form,&$form_state) {
$form_state['complete form']['Input type']['file']['#file'] = NULL;
$form_state['rebuild']=TRUE;
return;
}

Neither the submit nor the callback functions seems to be refreshing my form. Setting the file value to NULL has not had an effect either. 

I don't know what else to try. Cheers!

I'd like to clear the managed file field each time the contents are sent off for further processing on submit. The callbacks work fine, but I have repeatedly come unstuck in my goal of having a "fresh" form everytime I need to submit a new image.

The form is defined thus:

function        mymodule_form($form, &$form_state) {

$form['Input type'] = array(
    '#type'=>'fieldset',
    '#title'=>'Upload your image'
);

$form['Input type']['file'] = array(
    //file left in non-permanent state for testing purposes
    '#type' => 'managed_file',
    '#title'=> t('Upload image'),
    '#description' => t('Choose an image to upload. Format must be gif, png, jpg, and may not exceed 2MB in size. Press Submit to confirm your selection.'),
    '#upload_validators' => array(
        'file_validate_extensions' > array('gif png jpg jpeg'),
        'file_validate_size'=>array(512*512*512),
    ),
    '#upload_location'=>'public://mymodule_uploads',
);
       
$form['Input type']['submit'] = array(
    '#type'=>'submit',
    '#value' =>t('Submit'),
    '#submit'=>array('mymodule_clear_image_submit'),
    '#ajax' => array(
            'callback'=> 'mymodule_update_image_callback',
            'wrapper'=>'somediv'
        ),
);
return $form;
}
function        mymodule_update_image_callback($form,&$form_state) {
$picture_settings = array( 
        'image' => file_create_url($form['Input type']['file']['#file']->uri)
        );
    drupal_add_js(array('mymodule' => $picture_settings),'setting');
 
    return;
}

function        mymodule_clear_image_submit($form,&$form_state) {
$form_state['complete form']['Input type']['file']['#file'] = NULL;
$form_state['rebuild']=TRUE;
return;
}

Neither the submit nor the callback functions seems to be refreshing my form. Setting the file value to NULL has not had an effect either. I don't know what else to try. Cheers!

I'd like to clear the managed file field each time the contents are sent off for further processing on submit.

The callbacks work fine, but I have repeatedly come unstuck in my goal of having a "fresh" form everytime I need to submit a new image.

The form is defined thus:

function mymodule_form($form, &$form_state) {

$form['Input type'] = array(
    '#type'=>'fieldset',
    '#title'=>'Upload your image'
);

$form['Input type']['file'] = array(
    //file left in non-permanent state for testing purposes
    '#type' => 'managed_file',
    '#title'=> t('Upload image'),
    '#description' => t('Choose an image to upload. Format must be gif, png, jpg, and may not exceed 2MB in size. Press Submit to confirm your selection.'),
    '#upload_validators' => array(
        'file_validate_extensions' > array('gif png jpg jpeg'),
        'file_validate_size'=>array(512*512*512),
    ),
    '#upload_location'=>'public://mymodule_uploads',
);
       
$form['Input type']['submit'] = array(
    '#type'=>'submit',
    '#value' =>t('Submit'),
    '#submit'=>array('mymodule_clear_image_submit'),
    '#ajax' => array(
            'callback'=> 'mymodule_update_image_callback',
            'wrapper'=>'somediv'
        ),
);
return $form;
}
function mymodule_update_image_callback($form,&$form_state) {
$picture_settings = array( 
        'image' => file_create_url($form['Input type']['file']['#file']->uri)
        );
    drupal_add_js(array('mymodule' => $picture_settings),'setting');
 
    return;
}

function mymodule_clear_image_submit($form,&$form_state) {
$form_state['complete form']['Input type']['file']['#file'] = NULL;
$form_state['rebuild']=TRUE;
return;
}

Neither the submit nor the callback functions seems to be refreshing my form. Setting the file value to NULL has not had an effect either. 

I don't know what else to try. Cheers!

Source Link
Alex
  • 35
  • 6

Clear managed_file field on submit

I'd like to clear the managed file field each time the contents are sent off for further processing on submit. The callbacks work fine, but I have repeatedly come unstuck in my goal of having a "fresh" form everytime I need to submit a new image.

The form is defined thus:

function        mymodule_form($form, &$form_state) {

$form['Input type'] = array(
    '#type'=>'fieldset',
    '#title'=>'Upload your image'
);

$form['Input type']['file'] = array(
    //file left in non-permanent state for testing purposes
    '#type' => 'managed_file',
    '#title'=> t('Upload image'),
    '#description' => t('Choose an image to upload. Format must be gif, png, jpg, and may not exceed 2MB in size. Press Submit to confirm your selection.'),
    '#upload_validators' => array(
        'file_validate_extensions' > array('gif png jpg jpeg'),
        'file_validate_size'=>array(512*512*512),
    ),
    '#upload_location'=>'public://mymodule_uploads',
);
       
$form['Input type']['submit'] = array(
    '#type'=>'submit',
    '#value' =>t('Submit'),
    '#submit'=>array('mymodule_clear_image_submit'),
    '#ajax' => array(
            'callback'=> 'mymodule_update_image_callback',
            'wrapper'=>'somediv'
        ),
);
return $form;
}
function        mymodule_update_image_callback($form,&$form_state) {
$picture_settings = array( 
        'image' => file_create_url($form['Input type']['file']['#file']->uri)
        );
    drupal_add_js(array('mymodule' => $picture_settings),'setting');
 
    return;
}

function        mymodule_clear_image_submit($form,&$form_state) {
$form_state['complete form']['Input type']['file']['#file'] = NULL;
$form_state['rebuild']=TRUE;
return;
}

Neither the submit nor the callback functions seems to be refreshing my form. Setting the file value to NULL has not had an effect either. I don't know what else to try. Cheers!