During my module install I insert a custom member field into the EE database. It does appear in the member registration form as it should but no data is entered into the exp_member_data table upon submit.
If I don’t install the custom member field through the module install sequence but add it manually through the CP all works as it should. Below the insert statement I use.
$sql[] = "INSERT INTO exp_member_fields (m_field_id, m_field_name, m_field_label, m_field_description, m_field_type, m_field_list_items, m_field_ta_rows, m_field_maxl, m_field_width, m_field_search, m_field_required, m_field_public, m_field_reg, m_field_fmt, m_field_order) VALUES ('', 'company_code', 'Company Code', 'If you have received a Company Code from your Company please enter it here.', 'text', '', '10', '50', '100%', 'y', 'n', 'n', 'y', 'xhtml', '1')";
Anyone any idea what is happening?
You need to run an ALTER TABLE query on the exp_member_data table as well as add the field into the exp_member_fields. Custom weblog fields work similarly.
When you add a custom member field through the CP five queries occur. You can see the first at line 3414 of the cp.members.php file.
The query you are missing is this one (line 3487):
$DB->query("ALTER table exp_member_data add column m_field_id_{$DB->insert_id} text NOT NULL");
$DB->insert_id will give you the main index of the record just created (in this case the custom field in exp_member_fields).
There is quite a bit that goes on in addition to the above when you create or edit a custom member field. I would check out the cp.members.php file and make sure that your module is behaving well in this area based on what you need it to do.
It may be easier to simply require that a person using your module create the field themselves. But I’ll leave that up to you to decide. 😊
Jamie
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.