Pass multiple select values from your website to Salesforce.com

Apr 26 2010 Published by under Quick tips, Site design, Technote

If you’re integrating your website with Salesforce.com you may need to capture multiple select values. Unfortunately, Salesforce doesn’t accept an array of values (the way PHP sends multiple selects when a form is submitted) so it truncates the values it receives so only the first value gets through. I recently solved this issue when I was building a form for a client.

Salesforce needs a single

&var=val

pair for each of the values in the same select. So, we need to create something that looks like

&var=val1&var=val2&var=val3...

The php implode() function is very helpful here so we could just pass the array from the form to a php file and do something like

implode("&val=" $_POST['mySelect']);

It would be sensible to urlencode the values of the form data to make sure it arrives safely. So, we need to urlencode the values after they’ve been imploded. If we simply urlencode the array, we no longer have an array and it’s pretty useless.

To send data from the website to Salesforce, I pre-processed the data and sent the request ‘manually’ so my chain of events looked something like this:

Form on website >> php data manipulation >> php creation of POST >> Salesforce.com object

If you have any tips about integrating your website with Salesforce, please drop me a line.

Adwords advice