Reputation: 917
function Mymodule_user($op,&$edit, &$account, $category = NULL) {
switch ($op) {
case 'register':
$result = db_query("SELECT id,name FROM {sites} ORDER BY name");
while($row=db_fetch_array($result)) {
$sites[$row['id']] = $row['name'];
}
$form['site_select'] = array(
'#type' => 'select',
'#title' => t('Select your site'),
'#options' => $sites,
)
return $form;
case 'insert':
//How to take the $form values from above and use in my query to
//write to my own table while writing to the standard 'users' table?
db_query("INSERT INTO {another_table} (site_name) VALUES ('%s')",
$form['site_select']);
);
When the user hits the SUBMIT button when creating a standard Drupal account, how do I pass my custom field value of $form['site_select'] to my case 'insert' so that I can write this to 'another_table'. The regular user data such as username and password needs to continue to write to the default 'users' table.
Q: Why not just let Drupal serialize and save your data to the 'users' table in the 'data' field as it normally does?
A: Because I want to be able to AJAX-ify and use autocomplete in another Drupal form, as well as query specific custom fields in MySQL. MySQL cannot serialize/unserialize. For example, "SELECT DISTINCT site_name FROM another_table"
Upvotes: 0
Views: 514
Reputation: 2052
You're probably gonna want to alter the user_register form in order to add your own callback function to that form's #submit property, like:
<?php
/**
* Implementation of hook_form_FORMID_alter().
* @param $form
* @param $form_state
* @return void
*/
function MYMODULE_form_user_register_alter(&$form, &$form_state) {
$form['#submit'][] = 'MYMODULEs_own_register_submit_callback_func';
}
And then in the callback you're going to have $form_state
filled with whatever the user filled into the form (including the value for the extra site_select field element which you added in your hook_user implementation):
<?php
function MYMODULEs_own_register_submit_callback_func(&$form, &$form_state) {
// Do stuff with $form_state['values'], i.e $form_state['values']['site_select'], etc.
}
Upvotes: 1