Output database fields into custom form fields


(Steve) #1

Hi all,

I am currently working on connecting a database table to a Squiz custom form. What I am trying to do is based on a query (lookup logged in user), output some fields into a form (e.g. organisation area, position etc.)

I have a separate database (MySQL) which houses a table with information based on username.
Users log into our online form and the basic global attributes are available (first/last name, username, email)

I understand I will need a DB connector (data source?) but am struggling with how

  1. I can use the logged in username to query the database - in query builder it didn’t work using the global key replacement
  2. Using the retrieved information from the database and adding it as a default value into form fields

Part of the reason I’d like to have the content added to form fields is in case there is a need to make alternations e.g. add to the existing content.

Any help/guidance would be appreciated

Thanks
Steve


(Tarman) #2

@ooomp

  1. I can use the logged in username to query the database - in query builder it didn’t work using the global key replacement
  • How are you trying to use the global keywords in query builder? Any example of using global keywords on query builder.

(Steve) #3

@tmalla
So what I had initially tried was using %globals_user_attribute_username% as part of the query
When run, no shadow assets came through.

So I figured that it may not be possible?

I have also tried using a dynamic variable but unsure this works either?


(Chiranjivi Upreti) #4

You will need define a Dynamic Variable with source set as “Current User” => Keyword “asset_attribute_username”. Then use that dynamic var in the Query Builder. See the manual for details: https://matrix.squiz.net/manuals/data/chapters/db-data-source#Dynamic-Inputs-Screen

  1. Using the retrieved information from the database and adding it as a default value into form fields

This might require bit of implementation (which I am not expert on). If you could somehow set the data source entries in the appropriate global vars (maybe Set Session trigger action?), then use those global vars (global keywords) as default in the form fields.


(Steve) #5

@Chiranjivi_Upreti Thanks #1 worked! The dynamic input worked by setting the keyword, I had tried other combinations but not that facepalm

The next bit #2 is where my problem lies. I’ll take a look into global vars and triggers, surely there must be a way (outside of asset listings) to retrieve external DB fields and display them.