Make a button post data on General Settings page

Topics: Writing modules
Developer
Oct 9, 2011 at 7:10 PM
Edited Oct 9, 2011 at 8:33 PM

Hi all!

I'd like to have a button on the General Settings page that should trigger a post to a controller action. In other words, the button should post a custom data to another page. How would you do that properly? The button is part of a SiteSettings part, laid out from a driver.

If I make the button a submit one, it will submit the whole settings form, but this would be wrong. The button also could have some javascript, but using JS to post data seems just wrong (as it wouldn't be unobtrusive JS). The button could be also just a simple link, invoking the action with a GET, but as the action would alter the state of the application, this would be incorrect in the sense of HTTP. What would you advise? I haven't seen any examples of such functionality.

Coordinator
Oct 10, 2011 at 8:19 PM

There are actually other places in the admin where we do that, and the simplest is to do it with JavaScript. It does have the disadvantages you cite but as there already is a surrounding form and html doesn't play well with nested forms, it may be your cleanest option. The option of sending the whole form would work, but you would still need javascript to change the action for the form, sooo....

Developer
Oct 16, 2011 at 12:18 PM

Thanks, I actually have done it with JS (by making an AJAX call).