K
K
Kirill Parasotchenko2016-01-22 12:06:25
PHP
Kirill Parasotchenko, 2016-01-22 12:06:25

Why does remove button not work for managed_file drupal 7?

Created a form with managed_file. The remove button doesn't work. When you click on it, the file field does not appear and the rendered image does not disappear. What to do???
I have apache 2.4/php 7/myslq 5.

$form['profile']['my_module_custom']['my_module_file'] = array(
      '#type' => 'managed_file',
      '#upload_location' => 'public://',
      '#title' => t('File'),
      '#theme' => 'my_module_medium_upload',
      '#upload_validators' => array(
          'file_validate_extensions' => array('gif bmp png jpg jpeg'),
      ),
      '#attributes' => array(
          'multiple' => 'multiple',
      ),
  );



function theme_my_module_medium_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 src="' . file_create_url($element['#file']->uri) . '" />';
    $output .= '</span><input type="submit" id="edit-' . $element['#name'] . '-remove-button" name="' . $element['#name'] . '_remove_button" value="Remove" class="form-submit ajax-processed">';
    $output .= '<input type="hidden" name="' . $element['#name'] . '[fid]" value="' . $element['#file']->fid . '"></div></div>';
    return $output;
  }
}


function my_module_theme() {
  return array(
      'my_module_medium_upload' => array(
          'render element' => 'element',
      )
  );
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Parasotchenko, 2016-01-22
@Taiyonoryoshiy

it was in $form['#tree'] = true, when I removed it everything worked. maybe someone knows why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question