2

using drupal with lightbox2 to open a form. this form is from a custom module.

the module has a setting: 'onsubmit' => 'return form_submission(this);' and that appears to be working correctly.

I've included the functions.js in the theme.info file and it's showing up, i can open that file and see the function.

for some reason, i keep getting "form_submission not a function" when i do submit the form.

if(Drupal.jsEnabled)
{
$(document).ready(function() {
    // Call back function for AJAX call

        var form_submission = function(responseText) {
            alert (responseText); 
        }

        // preventing entire page from reloading
        return false;
    });

}
Kevin
  • 13,153
  • 11
  • 60
  • 87
eriksays
  • 130
  • 1
  • 6

3 Answers3

1

Your form_submission function is local to the anonymous function it's inside (ie the document ready function).

You need to declare the function in a global scope, outside of the document ready. You at least need to declare the variable form_submission. You will then be able to attach the function on to it wherever you wish.

Leon
  • 11
  • 1
  • Welcome to SO, but it seems you answered a question from 2010 :/ – hugomg May 25 '11 at 17:16
  • Lol, well always good to get something answered properly. Strange that this was on the first page of 'unanswered' questions if it was so old. – Leon May 26 '11 at 09:03
0

form_submission has to be a defined function.

function form_submission(data) {
   // action code
}

or also try

var form_submission = new function(data) {
   // action code
}
Kevin
  • 13,153
  • 11
  • 60
  • 87
  • thanks -- but something else is going on. i can add the function between script tags right above the form and still no luck. i tried both function declaration techniques you mentioned – eriksays Jun 16 '10 at 16:41
  • If you put an alert right after if(Drupal.jsEnabled), does it appear? Is that condition true? – Kevin Jun 16 '10 at 17:20
0

Not that this is the perfect answer, but I removed the function from within the document.ready jquery wrapper and it picked up on it.

eriksays
  • 130
  • 1
  • 6