Register form - autocomplete select options from a table/column in the database

Permalink 2 users found helpful
I'd like to add a Select field in the Register form which pulls data from a table in the database. Which file would I add this to?

 
JohntheFish replied on at Permalink Reply
JohntheFish
You would need to set the selection up as an attribute, then add the attribute to users and require it on register.

This may be a standard select attribute, or possibly a custom attribute you will have to code. All depends on your data.
jrenza replied on at Permalink Reply
I have that set up. But currently I'm 'hard-coding' sample values. I need to get 'under the hood' to tell it to pull in the data from the database. That's my issue.
JohntheFish replied on at Permalink Reply
JohntheFish
You will need to create a new attribute type (php code).

For this kind of attribute I usually inherit from a text or numeric attribute - depends on whether I want to store a database id or a label for the selected value. The attribute form would then populate a select input from your database table.
jrenza replied on at Permalink Reply
You mean custom code a new attribute type not 'choosing' a new attribute type from available in c5 admin? Which file can I custom code something like that?
jrenza replied on at Permalink Reply
I'm reading about creating a new block type. Is that what you are referring to?
JohntheFish replied on at Permalink Reply
JohntheFish
Attributes, not blocks
https://documentation.concrete5.org/developers/attributes/overview...

That discusses developing a complete attribute type from scratch. You can likely start by inheriting/extending an existing attribute such as text or number. Doing so is usually a lot easier because most of the difficult work is inherited and you don't need to provide a value entity.
jrenza replied on at Permalink Reply
Thanks for your response and help. You say to inherit/extend an existing text, or number attribute, should/could I use a 'select' attribute since it's an 'Options List'?
Also: is this what you are referring to?
https://documentation.concrete5.org/developers/attributes/creating-c...
JohntheFish replied on at Permalink Reply
JohntheFish
Select attributes are very complicated in comparison to text or number.

Think of what you need for data:
- list of options - comes from your table, presented in a select dropdown
- storage for what is selected - a string or id

You don't need all the Select attribute complexity for storing lists of options in secondary tables.
jrenza replied on at Permalink Reply
Cool, I get it. So what about populating the database? I see the Register form select pulls from a couple of the 'attribute' tables in the db. I have 4000+ values in this list, what's the best way to implement that? Populate the existing tables, or create a new table with those values? I assume populating the existing tables, although a more involved way, is probably the best, right?
JohntheFish replied on at Permalink Reply
JohntheFish
You have now changed the original problem. It is no longer "which pulls data from a table in the database". It is now "import my data [and use it in a select]". Different problem. Possibly different solution. If you have to import the data, maybe it would be better imported into an existing select attribute!

You need to describe your data and overall problem in more detail.
jrenza replied on at Permalink Reply
I apologize, yeah I should've specified that part. So, I just pull in the 4000+ values into the 'atselectoptions' table with appropriate 'displayOrder' and 'avSelectOptionListID' values? And I was hoping to autocomplete/ajax the values as the user starts typing not just having a huge list popup at once.
JohntheFish replied on at Permalink Reply
JohntheFish
There are some variations of select attributes that use a select2 that allows a user to start typing and a subset of options matches up. I don't know if any of them are ajax. For 4000 options, its not that big a download (less than the average image), so perhaps ajax would be un necessary.