Skip to content

Instantly share code, notes, and snippets.

@fastmover
Created June 24, 2014 16:10
Show Gist options
  • Select an option

  • Save fastmover/8244529593de55adaf6b to your computer and use it in GitHub Desktop.

Select an option

Save fastmover/8244529593de55adaf6b to your computer and use it in GitHub Desktop.
Auto fill GravityForms for testing
jQuery('.gfield').each(function() {
if( jQuery(this).find('.ginput_container').length && jQuery(this).find('.ginput_container').find('input').length && ( jQuery(this).find('.ginput_complex').length == 0 ) ) {
var Label = jQuery(this).find('label').text();
var filler = "";
switch(true) {
case String(Label).search(/first/i) != -1:
filler = 'Test First Name';
break;
case String(Label).search(/middle/i) != -1:
filler = 'Test Middle Name';
break;
case String(Label).search(/last/i) != -1:
filler = 'Test Last Name';
break;
case String(Label).search(/phone/i) != -1:
filler = '(0123)456-7890';
break;
case (String(Label).search(/email/i) != -1 || String(Label).search(/e-mail/i) != -1):
filler = 'test@gmail.com';
break;
}
Label = "";
jQuery(this).find('input').val(filler);
} else if ( jQuery(this).find('.ginput_complex').length ) {
jQuery(this).find('.ginput_complex').find('span').each(function() {
if(jQuery(this).find('input').length) {
var Label = jQuery(this).find('label').text();
switch(true) {
case String(Label).search(/street/i) != -1:
filler = '1234 Test Lane';
break;
case String(Label).search(/city/i) != -1:
filler = 'Testicity';
break;
case String(Label).search(/state/i) != -1:
filler = 'Test State';
break;
case String(Label).search(/zip/i) != -1:
filler = '54321';
break;
}
} else if ( jQuery(this).find('select').length ) {
var Label = jQuery(this).find('label').text();
if(String(Label).search(/country/i) != -1) {
jQuery(this).find("select option").filter(function() {
return jQuery(this).text().search(/united states/i) != -1;
}).attr('selected', true);
}
}
jQuery(this).find('input').val(filler);
});
}
});
@Houston-Brown

Copy link
Copy Markdown

How do I get this to work on a form. Where do I set this up?

Many thanks,
Houston

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment