Multiple Entries to Registration Dropdown

Sole Trader Forum

New member
Hi,

I need to add a couple of dropdown boxes to our user registration using the custom fields feature. The problem is, I need to add a lot of entries (counties and trade sectors) and the current way of doing this in the admin panel involves adding each entry manually and then clicking add.

Is there a way I can add a whole list (copy and pasting) for the dropdown selections? If not via the backend necessarily, maybe adding manually to the Database?

Any help would be great!

Thanks!
 
Well...

In the database, field choices are turned from this:

Code:
array( 
    'AF' => 'Afghanistan', 
    'AL' => 'Albania', 
    'DZ' => 'Algeria', 
    'AS' => 'American Samoa')

Into this:

Code:
a:236:{s:2:"AF";s:11:"Afghanistan";s:2:"AL";s:7:"Albania";s:2:"DZ";s:7:"Algeria";s:2:"AS";s:14:"American Samoa";

So it takes a PHP array and serializes it to store it in a blob in the database.

I can provide more assistance later.
 
The options are stored as a serialized array in the database (xf_user_field.field_choices). They can't be directly queried. A custom script is required to manipulate those values in the database.

This script serves as a good code example of the kind of script you need (assuming you are programmer):

http://xenforo.com/community/thread...uld-extend-current-upgrade.30768/#post-365248

I'm not unfortunately! It looks complicated :D

I thought it seemed like a strange way to add drop down options, but I'm assuming they have their reasons for it?

Is there maybe a way I can create a simple script to serialize a list of data and then add it to the database manually, or am I misunderstanding how this works?
 
I forgot about this all until someone liked my post :p

I found this website: http://www.countries-list.info/Download-List

From there I generated this serialized list of countries. You could create your custom user field for countries with a couple of options, then using PHP My Admin write a query to update the correct row with this attached data.

That's the easy one.

For anything else you wish to do, as per my previous post, you need to create an array of data like this:

Rich (BB code):
$data = array(
'item1' => 'Item 1',​
'item2' => 'Item 2'​
);

You'd then need a PHP script that serializes that which would look something like:

$serializedData = serialize($data);

Again, once you've got that serialized data you could insert it into the database.
 

Attachments

Thanks for your help! I ended up using a tool I found that serializes data, which might be handy if anybody else needs to do this:

http://www.functions-online.com/serialize.html

I then created an excel spreadsheet so my data was displayed in 3 columns like:

'1' => 'Data',

which allowed me to copy my list into the third column (I set up custom cell formatting so it automatically added the ' ', to each item) then copied it into the serializer and Executed an SQL query like this:


UPDATE xf_user_field SET field_choices = 'DATA FROM SERIALIZER TOOL HERE' WHERE field_id = 'country'

on the field xf_user_field.field_choices

(make sure you create the field first and create a test dropdown field. Also change 'country' above to the id of your custom field)
I hope this comes in handy for anybody else that needs to add a large drop down list on their signup page.
 
Another question I have regarding this, if anyone can help is;

How do I display the dropdown 'Text' rather than the 'value' on the members page? Using {$user.customFields.county} displays the 'value' of the dropdown rather than 'Text'.

Any help with that would be great!
 
Another question I have regarding this, if anyone can help is;

How do I display the dropdown 'Text' rather than the 'value' on the members page? Using {$user.customFields.county} displays the 'value' of the dropdown rather than 'Text'.

Any help with that would be great!

Where are you displaying the fields?

The display HTML may be useful here:

Admin CP -> Users -> Custom User Fields -> [click the field] -> General Options: Value Display HTML

Or this code may be useful for manual placements of fields (on profile pages in this example):

http://xenforo.com/community/threads/how-do-i-add-elements-profile-sidebar.35721/#post-406380

You can see in this example that it uses template helpers to get the title and value of the field instead of directly showing the raw value stored in the user record. That enables the Value Display HTML.
 
Perfect, that's exactly the code I needed! I was displaying the information on the members list page / the connections page.

Thanks very much for your help Jake / Chris. I think I'm all set with this now!
 
Top Bottom