Hello,

I have successfully added a several checkboxes to the pre-existing user_profile form, through template.php. (Unfortunately the Profile module will not accomplish what I need.)

Now I need to be able to save this information to the database...obviously. I have read many entries on this (http://drupal.org/node/169815, http://www.lullabot.com/articles/modifying-forms-5-and-6), however I'm still a little lost.

Could anyone point me in the right direction as to how to use a hook or other function to be able to do this?

Thanks

JP

Comments

DGvNp0niToyRspXaaqx3PiQBMn66QXyAq5yrNHpz’s picture

Here is some code I am working with, mytheme has been replaced in my real code. Just to get a general idea of where I'm at

/**
 * Updates the default `User Profile` form
 */
 function mytheme_user_profile_form($form) {
   
  $form['account']['name']['#title'] = t('Login ID'); 

  $form['subscription_53'] = array(
    '#type' => 'checkbox',
    '#name' => 'subscriptions[53]',
    '#id' => 'edit-subscription-53',
    '#title' => 'My Label'
  );

  $form['update_subscriptions'] = array(
    '#type' => 'hidden',
    '#id' => 'update-email-subscriptions',
    '#name' => 'update-email-subscriptions',
    '#value' => 'update_subscriptions_submit'
  );
 
  return drupal_render($form); 
 }
 
 function update_subscriptions_submit($form_id, $form_values) {
   $sql = "INSERT INTO {subscriptions} VALUES ('%d', '1', '1')";
   $update_subscriptions = db_query($sql);
   if ($update_subscriptions) {
     drupal_set_message('Your email subscription preferences have been updated');
   }
 }