Autocomplete during registration via external API

2 years 2 months ago #328739 by activha
Hi

I was wondering whether it could be possible to add an autocomplete feature to automatically get the name, address and legal information from a company when it registers, but by using an external API for all (french for now) registered companies.

Ideally I'd like to use the API of societeinfo.com/api-doc/#get-company to first use the autocomplete feature in the cb_company field and then use the json results to populate the other cb fields required at registration.

They have a GitHub example at github.com/aonnen/societeinfo-sandbox

Could you give me some hints at how to integrate this in cb_fields ?

Should I use an autoaction ? or only the code auto complete of the cb field ?

The API will return a json field like the ones displayed on the page, so how can I match cb fields with this ?

Do you have examples of code somewhere ?

Thanks

Please Log in to join the conversation.

2 years 2 months ago #328747 by krileon
CB Code Field provides PHP based autocomplete. You can use whatever PHP code you want, including making an HTTP call to an external service, to handle your autocomplete.

Should I use an autoaction ? or only the code auto complete of the cb field ?

You won't need CB Auto Actions for this.

Do you have examples of code somewhere ?

Simple example as follows. Sorry, can't help you with the rest as we do not provide custom coding assistance. You'll need to code the HTTP call, processing it, etc.. yourself.

if ( strpos( $value, 'pass' ) !== false ) {
	return [ 'Pass_1' => 'Pass 1', 'Pass_2' => 'Pass 2', 'Pass_3' => 'Pass 3', 'Test_4' => 'Pass 4', 'Test_5' => 'Pass 5', 'Test_6' => 'Pass 6' ];
} else {
	return [ 'Test_1' => 'Test 1', 'Test_2' => 'Test 2', 'Test_3' => 'Test 3', 'Test_4' => 'Test 4', 'Test_5' => 'Test 5', 'Test_6' => 'Test 6' ];
}

This simple example shows the Pass autocomplete result set if the fields value is "pass" otherwise it shows the Test result set.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.182 seconds

Facebook Twitter LinkedIn