I have form which i call like this:

module_load_include('inc', 'node', 'node.pages');
$new_blognode = new stdClass();
$new_blognode->type = 'projekti_resurssit';
node_object_prepare($new_blognode);
$output = drupal_get_form('projekti_resurssit_node_form', $new_blognode);
return $output;

The code is in node which is shown by views as an attachment to another view. I have also tried to put the code to footer of view(removing the need for attachment), but same thing.

Now, when user submits the node, it usually gets created two or even three times(sometimes only once)!
If i check the "remove form after submit" thing, it works correctly, but sadly it is not an option for me.

Any clue what's happening? This is really bad thing for me right now, and i'm completely lost!

Comments

kvvnn’s picture

A form of mine is submitting twice.

I am using

	$form['#ajax'] = array(
                'enabled' => TRUE
         );

within a form in my module that saves some DOM values into the database. I have not investigated whether this is the cause of 'disable redirect' , as I think I need to create a plugin to do so (and haven't had time to do that).

Will be testing and updating, though, :)

drupalina’s picture

Subscribing.
I have the same problem. I have an auto-refreshing View of "question" content types, and a Form Block on top of that View so that people can submit questions. The idea is to create a Twitter/Facebook style form and view ... so that people submit a question and their question immediately appears below the form. Instead, what I get is that 3, 4, or sometimes even 5 versions of that same question appear. Making the form disappear after posting (in Ajax settings) does not resolve this problem. This bug is pretty critical.

brooksbrown’s picture

I also was having this problem in the exact same scenario. I assume that the any extra clicks occurring between the submit hook call and the redirect hook call are actually being submitted so I just disabled the submitter during the interval between the calls. This wasnt tested thoroughly but seems to work.

Here is my fix:

add this hook block to ajax_disable_redirect.js

  if (hook === 'submit') {
	args.submitter.attr('disabled', 'true');
  }

then inside the redirect block
add the line

args.local.submitter.removeAttr('disabled');

after

args.local.form[0].reset()

complete function with changes:

Drupal.Ajax.plugins.disable_redirect = function(hook, args) {
console.log(hook);
console.log(args);
  if (hook === 'submit') {
	args.submitter.attr('disabled', 'true');
  }

  if (hook === 'redirect') {
    if (args.options.disable_redirect === true) {
      args.local.form[0].reset();
	  args.local.submitter.removeAttr('disabled');
      //IE
      $('.form-item select', args.local.form[0]).attr('selectedIndex', 0);
      if (args.options.remove_form === true) {
        args.local.form.remove();
      }
      else {
        $('.form-item :input', args.local.form[0])[0].focus();
      }
      return false;
    }
  }
}
brendoncrawford’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

davibrosk, if you submit a patch for this, I will apply it.

bfr’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.49 KB

Thanks. I created a patch. It's created with with git format-patch, like they now should, so please commit it with this exact command:
git am < ajax-redirect-causes-forms-to-post-multiple-times-718070-5.patch

As i side note, you have files in the master branch. Master branch is deprecated and should be empty.

cluke009’s picture

I've pushed this patch up to my github branch. I am going to do some testing on this and try to get through a couple more issues and I will do a pull request.

bfr’s picture

Out of curiosity, why do have alternative branches in github? Why not use d.org repos?

cluke009’s picture

That is the way brendoncrawford recommended people contribute. Its right at the top of the project page.