Last active
August 29, 2015 14:08
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* BuboBox form callback module | |
* | |
* @author Wim Mostmans ([email protected]) | |
* @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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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