I'm trying to get a D7 form into a Bootstrap modal dialog. I had this working on D6, through a semi-straightforward process:
The jQuery code that's building and showing the modal does an $.ajax call to a url on my site to get the form contents -- something like /get_my_form/123. This request is picked up by a Drupal menu entry that makes a call to drupal_get_form() with the appropriate form function and various parameters. The usual Drupal form-creation thing.
There's a theme function for the form that does a couple of things and then sends the results back to jQuery by doing:
The ajax handler, which is expecting a json object, gets the results and sticks them into the body of the modal, and puts it up.
In moving this code to D7, I've been following the same route. It almost works, but the ajax call continually fails because the response string from the server includes the HTML from a page template, up to the point where the "exit" in the theming function kills the PHP request. That HTML is obviously not a expected part of the JSON object, but I can't figure out how to get rid of it. I've tried using drupal_json_encode in place of json_encode, and replacing the "print" statement with a call to drupal_json_output, but the page template stuff keeps coming. I'm definitely not adding it to what's produced in the theme function, so there must be some other part of Drupal that's squirting it out in ajax's direction.
Any ideas? This has REALLY been driving me crazy this afternoon. Thanks!