Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Integration Gravity Forms and Edmunds API WordPress

  • SOLVED

Hello there,

We have a gravity form [[LINK href="http://pomcar.com/work-request"]]here[[/LINK]].

First field is VIN#

We need users to enter a vehicle vin # and have the form use that number to pull information from [[LINK href="http://developer.edmunds.com/"]]Edmunds API[[/LINK]] in order to populate: year, make and model.

Thanks a lot!

Answers (1)

2015-02-19

Jeremy answers:

Are you looking for bids for a developer to write this for you?


intilabs comments:

Yes please.


Jeremy comments:

Please check your Private Messages for custom quote.


intilabs comments:

Jeremy, I just checked and have no messages from you.

Thanks


Jeremy comments:

Just sent.


Jeremy comments:

Here's a demo: http://gravityforms.myclientpreview.com/auto-make-models/


Jeremy comments:

You can use the Random VIN website to test: http://randomvin.com/


Jeremy comments:

I would implement this solution as a custom plugin but you could implement it in your functions.php and create a custom script in theme directory rather than a plugin file.

Writing a Plugin: http://codex.wordpress.org/Writing_a_Plugin

In your plugin file:

add_action( 'gform_enqueue_scripts', function( $form ) {
wp_enqueue_script('auto-script', plugins_url( "/js/custom.js", __FILE__), array( 'jquery' ), '1.0', true );
});


Going to use jQuery and gform_post_render Javascript hook to implement this solution:

Assign classesd to each of the input fields:

var vinClass = ".carVin input[type=text]";
var makeClass = ".carMake input[type=text]";
var modelClass = ".carModel input[type=text]";


No need to apply this to all forms, so to restrict it we are going to replace %Your_Form_Id% below with the id number of your form

Change %Your_API_Key% to your registered application API Key.

jQuery(document).bind('gform_post_render', function(event, form_id){

if(form_id == %Your_Form_Id%) {


autoMakeModel = function () {

var vinClass = ".carVin input[type=text]";
var makeClass = ".carMake input[type=text]";
var modelClass = ".carModel input[type=text]";

jQuery(vinClass).on("blur", function () {

var vin = jQuery(this).val();
var api_key = '%Your_API_Key%';

if (vinClass != '') {
jQuery.getJSON("https://api.edmunds.com/api/vehicle/v2/vins/"+ vin +"?manufactureCode={manufacturer code}&fmt=json&api_key="+api_key, function (result) {
jQuery(makeClass).val(result.make.name);
jQuery(modelClass).val(result.model.name);
} );
}

});
}

autoMakeModel();

}

});