I want to use a hidden profile field to hold an account balance. Do I need to check for a null value before accessing each time or I can I set up a default value somehow to initialize it to zero?

Comments

gdoteof’s picture

just to be clear, specifically what i want to is to set a default value for a profile field

gdoteof’s picture

also, any insight into why I cannot get replies in support forums would be useful

svogel’s picture

to both of your questions.
I'm interested in setting default values for profile fields as well. This would come especially handy when using checkbox-fields.
As to your second question. I think it's too many questions, too few people :-(
Maybe you have found a solution and can post it here?

After digging a bit, I found something that worked in my case.
I'd like to give the user a default-value for a checkbox, when the user opens the "profile"-form. By the way that's not a default-value that's inserted in the profile_values-table.
I got a custom module with user_hook:

function testmodule_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'load':
      if (!isset($account->profile_mailnotify)) {
        $account->profile_mailnotify = TRUE;
      }
      break;
  }
}

With this hook the default-value is set, if it is not set before. In case you want to store default-values profile_values for each registered user, you may have to do something in the user_hook for op "insert" or something like that.

Best regards
Stefan

WorldFallz’s picture

The only way I know to attempt this would be to use hook_form_alter on the user_register and/or user_profile forms in a custom module. If you don't want to or can't code, then you could use the content_profile module which opens up profiles to the full power and flexibility of cck nodes.

As for why questions don't get answered-- there's probably a lot of reasons:

  • question can be answered by the poster themself with just a smidgen of effort (ie 'is there a module for...')
  • too broad a question (ie "how do i build facebook?")
  • unclear question
  • not enough detail in the original post to answer the question (drupal version, module version, error messages, etc. Saying "it doesn't work" is useless).
  • stupid subject ('help me')
  • overuse of punctuation and/or capitals ('PLEASE HELP ME ?!?!?!?!?!?!??!?!?!')

Just to name a few. And of course, svogel, is correct-- there are far more people asking questions than answering them. So, when any of the above are true, it's simply more efficient to move on to a question you can answer than it is to reply requesting clarification or additional info.

Don't expect anyone to put more effort into answering your question than you are willing to put in asking it or attempting to help yourself before asking it.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz