0

I have a form in my drupal module. in my form, I have used manged_file field. form name is "difference_form" and I have created two functions. one is "function diffence_form" for form definitions. here is code:

function difference_form() {
  $validators = [];
  $form['new_image'] = [
    '#type' => 'managed_file',
    '#name' => 'new_personal_image',
    '#title' => 'New Image',
    '#description' => theme('file_upload_help', [
      'description' => 'Please insert your new image.',
      'upload_validators' => $validators,
    ]),
    '#upload_location' => $path,
    '#default_value' => variable_get('new_image', ''),
    '#upload_validators' => $validators,
  ];

  $form['submit'] = [
    '#type' => 'submit',
    '#value' => 'submit',
  ];

  return $form;
}

function difference_form_submit($form, &$form_state) {
  drupal_set_message('test_form_submit called');
}

and also I have created a block for this form in hook_block_view.

function customize_block_view($delta = '') {

  $block = NULL;
  $block['content'] = drupal_get_form('difference_form');
  $block['subject'] = 'Difference Form';
  return $block;
}

Form is rendered correctly, but when I click on submit button, submit function is not called.

I tried to debug my codes. I found if I remove file_managed field from form definition, submit function works.

also if I found if I renamed all difference_form to another name for example "test_form"

drupal_get_form('test_form'); function test_form(){....} and function test_form_submit(......

submit function works. it seems system is sensitive on "difference_form" only

I am thinking might the expression "difference_form" be blocked in database or somewhere else ?

  • Today, I made a test. I made a new Drupal 7 installation and installed my custom module. I faced submit handler works on new Drupal install with no problem. but exact codes in base project I see submit handler doesn't work. it seems file_managed causes form goes to black list and Drupal doesn't call submit handler. – Mehrdad201 Jun 16 at 16:15
0

I found the reason of this problem finally. It was as a result of jQuery code mistakes.

in form submission, I tried to disable submit button immediately after clicking. I had to change the coding because set button disable causes this problem.

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.