Skip to content

Instantly share code, notes, and snippets.

@madhermit
Last active August 18, 2016 16:15
Show Gist options
  • Save madhermit/8470fcb1a9938b422aede5b5dc2939f8 to your computer and use it in GitHub Desktop.
Save madhermit/8470fcb1a9938b422aede5b5dc2939f8 to your computer and use it in GitHub Desktop.
Formbuilder JS
$('#fb_xml').formBuilder();
$('.fb-save').click(function() {
//try to infer field name from label; otherwise FormBuilder gives it names like text-1231231231
$("ul#frmb-0 li").each(function(i) {
var label = $(this).find('.form-elements .label-wrap input').val();
var name_field = $(this).find('.form-elements .name-wrap input');
var slug = label.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-');
//add field to array so we are in effect namespacing these varaibles
//this is in response to a weird bug where WP was redirecting the form to the search page when a field was called 'name'
name_field.val( 'var[' + slug + ']' );
});
$('#contact_form_builder').submit();
});
##works
$('.frmb').on('blur','.fld-label', function() {
var label = $(this).val();
var name_field = $(this).parents('.form-elements').find('.name-wrap input');
var slug = label.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-');
//add field to array so we are in effect namespacing these varaibles
//this is in response to a weird bug where WP was redirecting the form to the search page when a field was called 'name'
//name_field.val( 'var[' + slug + ']' ); //formbuilder erases the brackets on blur on the name field
name_field.val( 'var_' + slug );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment