Populate Fields of a Form from a Different Database Table

Hi there,

I need to create a form that allows a user to submit data through. There are a couple of fields that should pre-populate based on the selection a user makes from a select / dropdown field.

I have a "client" list / table setup and populated; it contains fields such as "name", "email", "id", etc.

Basically, I need to be able to select an option from a dropdown field in a form. The dropdown field will pull from the "client" table using the "name" of the client as the values of the dropdown.

I also need to pre-populate a "field" field in the form for the email of the client. This is where I'm running into a roadblock.

How I have it setup is as follows:

1. Client table with the following fields: id, date time, account status (active or not = 1 / 0), account id (custom account id number), account number (custom account number), account name, title, first name, last name, email.

2. Issue table / form with the following fields: id, date time, company select (dropdown), company name, company email, issue text area

3. I had to pre-populate the "Company Select" dropdown with the account name from the "Clients" table. I did this via the DB Join element, set to be a "dropdown" field.

4. I needed to populate the "Company Name" field based on the company selected from the "Company Select" field. This worked easily enough using the JS plugin on the "Company Select" field and just inserting the value of the selected company as the value of the "Company Name" text field.

5. I also need to populate the "Company Email" field with the email of the company that's located in the "Clients" table.

However, doing this is where I hit the roadblock...

I haven't figured out how to load multiple sets of data from a table?should this be done as a join in the list? Or as how I'm doing it with the elements? As I mentioned, I was able to pretty easily set up doing it for one piece of data, but how do you do it for multiple?

Any further info you'd like me to provide, let me know. I appreciate your help :)

Thanks much!

Cheers

Kyle
 
Hi,

Solved this one myself - I set the "value" on the dbjoin element to be the email, and the "label" to be the company name. Then, I just wrote a little JS for each to spit out the values into the readonly fields. Given that this is a "closed" intranet environment, we're not concerned with scrapers and the emails being present, so it should be a good enough solution for the time being.... Still be interested to hear other, more scalable thoughts on this one though.. Separate lists for data (clients in one table, client emails in another???).

Cheers

Kyle
 
There is an Autofill form plugin which may do what you want (though it is apparently a maintenance headache for Fabrikar which may mean that it won't work in boundary / corner cases).

Alternatively, use calc field to lookup field values based on the dropdown value - set Ajax on and it will relook this up when you change the dropdown. If you want the user to be able to override the lookup value, then hide the calc field and use a JS change event to copy the value of this field to a matching input field. If you use JS to copy the data over, then don't forget also to fire a change event on the input field as these are only automatically issued when the user makes a change. (See this wiki entry for an example of this in price:change).
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top