I needed a custom field that couldn’t be provided by the core profile module (Select list populated from a SQL query). I was able to successfully add the field with proper options; however, I am unsure how to handle this new field once submitted.
From what I understand, I need to write a function that handles my SQL insert, and then call that function from a hook_form_alter submit button.
As of now, it is passing only the field name, not the value. And the field name is being serialized and stored in the ‘data’ field of the user table. I’m attempting to pass it to its own column.
Here is my code…
//takes value and inserts it to account field
function accountselect_submitaccount() {
db_query( "INSERT INTO {user} (account)
VALUES {account_name}" );
}
Then…
//call the above function using custom submit (I suspect this is the troubled area)
function accountselect_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'user-register')
$form['#submit'][] = 'accountselect_submitaccount';
}
To my knowledge, new fields are only added to the
datacolumn if there’s no column matching the field name. You should be able to just create a column ofaccountinto the user table and it’ll get populated with that data.As for the code you’ve posted, your submission function has a number of issues:
submit_function($form, &$form_state)gives you access to the$form_state['values']array.INSERTwill never work. You need anUPDATEquery.{account_name}in the query. You need to actually use the value from$form_state['values'].