0

I'm using a "managed file" to upload an image, which works fine, but if you want to remove the image by clicking on the "Remove" button, nothing happens.

 $form['logo'] = array(
    '#type' => 'managed_file',
    '#title' => 'Logo',
    '#default_value' => variable_get('logo', ''),
    '#theme' => 'mymodule_thumb_upload',
    '#upload_location' => 'public://my-files/',
    '#upload_validators' => array(
      'file_validate_extensions' => array('gif png jpg jpeg'),
      'file_validate_size' => array(0.3*1024*1024),
      'file_validate_image_resolution'=>array('100x100'),
    ),
);

I'm using a custom theme, and I just realized when I switch back to 'Seven' the button works. But what could be the problem?

0
function name_module_form() {
  $form['logo'] = array(
    '#type' => 'managed_file',
    '#title' => 'Logo',
    '#default_value' => variable_get('logo', ''),
    '#description' => t('Upload File'),
    '#upload_validators' => array(
      'file_validate_extensions' => array('gif png jpg jpeg'),
      'file_validate_size' => array(100 * 1024 * 1024),
    ),
    '#theme' => 'abc_thumb_upload',
    '#upload_location' => 'public://abc/',
    '#attributes' => array(
    'multiple' => 'multiple'
  ));
}

function name_module_theme() {
  return array(
    'abc_thumb_upload' => array(
    'render element' => 'element',
    'file' => 'name_module.module',
  ));
}

function theme_abc_thumb_upload($variables) {
  $element = $variables['element'];
  if (isset($element['#file']->uri)) {
    $output = '<div id="edit-logo-ajax-wrapper"><div class="form-item form-type-managed-file form-item-logo"><span class="file">';
    $output .= '<img height="100px" src="' . file_create_url($element['#file']->uri) . '" />';
    $output .= '</span><input type="submit" id="edit-' . isset($element['remove_button']['#name ']) . '-remove-button" name="' . isset($element['remove_button']['#name ']) . '_remove_button" value="Remove" class="btn btn-default form-submit ajax-processed">';
    $output .= '<input type="hidden" name="' . isset($element['remove_button']['#name ']) . '[fid]" value="' . $element['#file']->fid . '">';

    return $output;
  }
}
  • 1
    Hi and welcome to Drupal Answers. I would recommend you to improve the formatting of your answer and include more information on the reasoning behind your code. – Wtower Jan 8 '15 at 15:29

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.