3

Whilst not really an EE specific question, I have need to present the user with a Freeform and have them type in their unique ID# which relates to another channel full of "companies" but I'd like to be able to query the number they type in, match it against a "companies" unique ID and pre populate the rest of the fields.

I know their is no single answer but any guides anyone can offer would be invaluable at this point in time.I'm a bit of an ajax N00b to boot!

Recap:

  • Enter 10 digit unique ID
  • Query the "Companies" channel for ID
  • If found, populate forms address, suburb, state etc from Company/Channel/info
  • They can then get on with the remainder of the fields.
4

It would be difficult to lay out the full code here, but we do something similar, so let me try to point you in the right direction.

What you are looking for is normally referred to as "jQuery Autocomplete". A great example can be found here:

http://www.ramirezcobos.com/labs/autocomplete-for-jquery-js/

Or use jQuery along with jQuery UI with this: http://jqueryui.com/autocomplete/

The first plugin will get you most of the way there, but it does require some jQuery & PHP experience.

The way it works is as follows:

  • install the jQuery plugin on your server
  • modify the included PHP file to include a database call based on your criteria. The query would follow the logic, "Select all fields, for entries in the Company Channel, where the Custom ID field is equal to the ID passed from the search"
  • the above query and settings depend on your setup, and which jQuery plugin you use.
  • you add the jQuery Autocomplete code to the one specific 'search' field in your Freeform
    • when you have that working, typing in an ID will start autocompleting existing entries. You can specify in the PHP settings file which field to display in the result box.
  • Clicking on a result would then reload the page, passing the results as POST variables
  • you could then use the POST variable, the company ID for example, within your main channel or Freeform tags as a parameter

CAVEATS: - PHP knowledge needed to setup the PHP code - MySQL skills needed to build the query (very basic though) - You must be careful regarding customer security & privacy. Are you certain that you want to make public all of the "Company" data?

Check out the link above though, to assess how comfortable you are with this type of script. If not, it is somewhat trivial for an experienced developer.

Feel free to reach out for help here if needed.

Cheers,

Ira

| improve this answer | |
  • I may very well be chasing you down in the next few days! Thx for the outline too :) – stuartmcd69 Nov 27 '12 at 6:43
3

Something like MadeByHippo's post is a good starting point for querying the DB for the details and return the data that you need via AJAX. With channel data you would need a slightly more complex query but the basis is there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.