Formidable integration with Opensearch API

Integrating Wikipedia Opensearch API with a Form Builder

Recently I wanted to allow autocomplete search of Wikipedia from a form field and, based upon the selection, populate other fields with relevant data from Wikipedia. Thankfully there’s an easy button for this using the Opensearch API.

For this tutorial we will be autocompleting author info for a form using Wikipedia parameters based upon the selection from the automcomplete field.  For example, if the user searches Ernest Hemingway, it autocompletes based upon the existing Wikipedia article. Once the author name is selected, it autopopulates relevant fields from the Wikipedia article.

Wikipedia Opensearch API and Formidable

This is a tutorial that will be most suitable for developers but should also be useful for beginners looking to integrate Opensearch with a web form. For a quick background on how autocomplete works with Wikipedia Opensearch API see this article. You can find the parameters for the Opensearch API here.

I will use a WordPress-specific form builder called Formidable for this example but you could follow these directions for any web form.

Setup Your Form

  1. Once you’ve activated Formidable, click on Forms -> Add New
  2. Add seven single line text fields to your form:
    Name, Birth Name, Birth Place, Birth Date, Death Date, Author Image, Author Link
  3. Click Create

Integrating with Opensearch API

    1. Note the field ids of the seven fields you created
    2. Use a script along these lines. Note that you will replace field_entrykey and form_key with your relevant field and form ids or keys. Note that your searchInput field should be your search box. All of the other parameters will populate based upon what is selected in the searchInput field.

<script src=""></script>
<link rel="stylesheet" href="" />
<script src=""></script>
transition: opacity 200ms
var inputsMap = {
birthName: "#field_entrykey2",
birthPlace: "#field_entrykey3",
birthDate: "#field_entrykey4",
deathDate: "#field_entrykey5",
link: "#field_entrykey6",
photo: "#field_entrykey7",

valuesMap = {},
$searchInput = $("#field_entrykey1"),
$form = $("#form_key25");

source: function(request, response) {
{search: request.term},
function(data) {

valuesMap = {};
data[1].forEach(function(val, idx){
valuesMap[val] = data[3][idx].replace(/^.+?\/([^/]+$)/, "$1")

}, "jsonp");

select:function(event, ui){
function getContent(title ){
var result = {},


{titles: title},
//parse content

var content = JSON.stringify(resp).replace(/<!--[\s\S]+?-->/g, ''),
result = {
name: (content.match(/"title":"(.+?)"/) || [])[1] || "",
birthName: (content.match(/\|\s*birth_name\s*=\s*(.*?)\\n\|/)|| [])[1] || "",
birthPlace: (content.match(/\|\s*birth_place\s*=\s*(.*?)\\n\|/)|| [])[1] || "",
birthDate: (content.match(/\|\s*birth_date\s*=\s*(.*?)\\n\|/)|| [])[1] || "",
deathDate: (content.match(/\|\s*death_date\s*=\s*(.*?)\\n\|/)|| [])[1] || "",
photo: (content.match(/\|\s*image\s*=\s*(.*?)(\\n|{{)/)|| [])[1] || "",
if(!{ = (content.match(/\|\s*image1\s*=\s*(.*?)(\\n|{{)/)|| [])[1] || ""
var birthPlace = result.birthPlace.replace(/\[\[(.+?\|)?(.+?)\]\]/g, '$2'),
chunks = birthPlace.split(", ");

// = chunks.pop()
result.birthPlace = chunks.join(", ")


match = result.birthDate.match(/\|(\d\d\d\d)\|(\d\d?)\|(\d\d?)/)
result.birthDate = match[2] + "/" + match[3] + "/" + match[1]


match = result.deathDate.match(/\|(\d\d\d\d)\|(\d\d?)\|(\d\d?)/)
result.deathDate = match[2] + "/" + match[3] + "/" + match[1]

} = ""+title

getImage(, function(photo){
if(photo) = photo;
//set fields
$.each(result, function(key, val){
console.log('err', e)


function getImage(fileName, callback){
if(!fileName) return callback();

{titles: "File:"+fileName},
function(data) {
var pages = $.map(data.query.pages, function(val, key) { return val; }),
page = pages[0];

if(!page || !page.imageinfo || !page.imageinfo.length ) return callback();


}, "jsonp")

function setLoader(active){


Add to Form

  1. Click on Forms
  2. Select your form and select Settings -> Customize HTML -> After Fields
  3. Add your script to After Fields
    Add JS to After Fields in Formidable for Opensearch

If you’re looking to do the above with your own form and have particular parameters you would like to populate, you can use the WikiMedia API sandbox to start finding your parameters.


Leave a Reply

Your email address will not be published. Required fields are marked *