double posting/sending #2431

Closed
NestorAcevedo opened this Issue Sep 24, 2012 · 2 comments

Comments

Projects
None yet
2 participants

hi.

i've noticed that sending a form from mootools code, this makes a double sending of data from the same form. i have the following code:

window.addEvent('load', function() {
                new JCaption('img.caption');
            });
            window.addEvent('domready', function() {
                //Vamos a recibir el elemento formulario
                elementoFormulario = $("comente");
                //Vamos a a�adir un evento al formulario para cuando se env�e
                elementoFormulario.addEvent('submit', function(e) {
                   //primero voy a parar el evento para que no se env�e como lo har�a normalmente
                   e.stop();
                   //Aqu� podr�amos hacer acciones como mostrar la t�pica imagen de cargando de Ajax
                   //Luego definimos qu� hacer cuando se env�a el formulario
                   //Aqu� "this" se refiere al formulario sobre el que defino el evento
                   this.set('send', {
                      //onComplete sirve para definir qu� hacer cuando se recibe la respuesta
                      onComplete: function(respuesta) {
                                if(respuesta != "false") {
                                    //escribo la respuesta en la capa "comentario"
                                    $("post-comment").set('html', '<div class="comments">' + respuesta + "</div>");
                                    tinyMCE.execCommand("mceCleanUp", false);
                                    document.getElementById("correo").value = "";
                                    document.getElementById("titulo").value = "";
                                } else {
                                    alert("el codigo captcha es incorrecto");
                                }
                      }
                   });
                   //Env�o el formulario
                   this.send();
                });
            });

as can be seen XD in this code first i catch the form element for after make the submit addevent. into it, i stop the normal sending, define what to do when i get the response with oncomplete. in oncomplete, i catch if response is "false" or not, when is "false" i show an alert error, else, i put the response in a div. and the end i send the form. the logic is: stop the normal sending, set the send actions, and after, send the form.

the problem is that this is sending twice the same form content and i'm having in troubles for catch why. before 1.4.x (hehe i don't remember when begun to happen that) the sending were normal -one click, one sending-

Owner

arian commented Sep 24, 2012

Try to move the the onComplete 'option' outside the submit event. Each time you submit, it gets added again.

See http://jsfiddle.net/tMPDk/

arian closed this Sep 24, 2012

just i've changed the code according to suggested but the problem still
persists. you can check this in
http://nogardtools.com/nestorftp/joomla25/index.php?option=com_content&view=article&id=10&Itemid=266

filling the data, and after accesing to
nogardtools.com/nestrftp/joomla25/administrator

with user: test and pwd: 123, in Comente component menu, you will find
the message repeated.

El 24/09/2012 06:16 p.m., Arian Stolwijk escribió:

Try to move the the onComplete 'option' outside the submit event. Each
time you submit, it gets added again.

See http://jsfiddle.net/tMPDk/


Reply to this email directly or view it on GitHub
#2431 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment