0
votes

I have a custom module, this module generate a table with some buttons. When a button is clicked I load with Ajax a form a display it in a div. The hook menu to call that function is for example /myapp/get_form.

The problem comes when I have to save some data of the new generated div. I created that div to save the data with ajax ( $form['submit'] = array('#ajax' => array(...))), but this new form does not save the data with ajax, this form post the data to /myapp/get_form, but that is not the behaviour I need.

So I have 2 questions.

  1. How do I post data generated with ajax in this new form?
  2. Would be ok to save the data (node) with JQuery disabling the submit and using Ajax+JSON?

Thanks!

1

1 Answers

0
votes

You can use jQuery .submit method to prevent the default submission beahvior and handle it trought $.post

Notice that some fields/modules and #ajax stuff to require additional javascripts that are included in the full page load.

To get them you should retrieve them with something like $js_list = drupal_add_js() and add then to the current page with jquery (eg adding them as tags in the head of the current page.)

After the scripts are loaded call Drupal.attachBeahviors() to attach the newly loaded javascript functionality to the new form.