I have a non-ajax form for which I'm trying to execute a jQuery function after the form has been submitted and processed.

I don't need ajax for the form, but I do need to wait until 600 odd form fields have been processed before executing my jQuery function.

There are a lot of answers out there, but I can't quite figure them out.

Should I do this via ajax (even though not required for the form) or is there a better way to do it?

Given the form takes a good few seconds (10 or so) to process (more on mobile, etc.) how should I go about it?


Another go at explaining exactly what I'm trying to do.

  1. I have a form that collects 600+ pieces of data
  2. After the form has been submitted and processed, I need to open a new window that processes the data, displaying it graphically (via canvas) and then saves that canvas as an image to the user profile.

Because there is so much data that needs to be processed, I've elected to run everything in a new window, so if the user navigates away from the main window, their canvas is drawn and saved, etc. in the background.

It appears that jQuery is the only way to open this new window, and I have to execute this after the form submission (otherwise the canvas is drawn with pre-submitted data)

Of course, there could be a better end to end way to do it, but jQuery post form submit seems to be it.

  • When your form takes 10 seconds to submit for a single user on the platform you might run into a problem when there are multiple users trying to do that (php execution time, memory limit, ..). Maybe you consider using the batch API. With this you would tell the user that something is happening and not run into time or memory issues.
    – schlicki
    Feb 19, 2017 at 9:56
  • Thanks @schlicki - I haven't looked at batch operations before, but they might be the way to go.
    – Simo
    Feb 20, 2017 at 0:59

1 Answer 1


You can use Drupal.behaviors, which is fired upon page load.

function doSomething()
  // Do something

Drupal.behaviors.myModule = {
  attach:function() {
  • I'm not sure that page load would do (I could be wrong). Would this execute on the initial page load? it would need to be on the load after the form submission
    – Simo
    Feb 19, 2017 at 8:49
  • If your form doesn't use ajax, then it is submitted and processed when the page is loaded. This code will execute after the page is loaded.
    – Jaypan
    Feb 19, 2017 at 8:50
  • Close... While this does trigger after the form has been processed, it also triggers on the initial form load. I only need it after submission. I'm happy to do this via ajax if necessary, but would only be using ajax to trigger the function...
    – Simo
    Feb 19, 2017 at 8:58
  • Why don't you edit the original post and tell us what you are actually trying to do. Right now you've told us how you're trying to do it.
    – Jaypan
    Feb 19, 2017 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.