Skip to content

Instantly share code, notes, and snippets.

@Sitebase
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sitebase/c846038aefc0cfc78824 to your computer and use it in GitHub Desktop.
Save Sitebase/c846038aefc0cfc78824 to your computer and use it in GitHub Desktop.
BuboBox Javascript module that will post the user submitted form data to your server.
/**
* BuboBox form callback module
*
* @author Wim Mostmans (wim@bubobox.com)
* @license BSD
*
* Copyright (c) 2014 BuboBox
*/
window.bbbx_modules = window.bbbx_modules || []; // Make modules array if not yet exists
window.bbbx_modules.push(function(sandbox, $) {
var NAME = 'bbbx-form-callback';
var settings = $(bbbx_form_callback_tag).data();
/**
* This will send the meta data to the selected server
*/
function submit( e )
{
var meta = sandbox.getMeta();
$.ajax({
url: settings.callback,
data: meta
});
}
var exports = {
NAME: NAME,
/**
* Module is registered inside the BuboBox widget
*/
init: function() {},
/**
* Add listeners for certain actions that happen
* in the BuboBox widgets
*/
bind: function() {
sandbox.subscribe('plugin.form.proceed', submit);
},
/**
* Remove listeners we create in the bind function
*/
unbind: function() {
sandbox.unsubscribe(['plugin.form.proceed', submit]);
},
/**
* Clean up all stuff this module has created
*/
destroy: function() {
this.unbind();
}
};
return exports;
});
// Store the current script tag reference
var bbbx_form_callback_tag = document.currentScript;
<html>
<head>
<script src="bbbx-form-callback.js" data-callback="http://httpbin.org/get"></script>
</head>
<body>
<!-- your BuboBox widget snippet -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment