Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount! Get 20% off now with code SPOOKY-2024!

Assign values to radio button fields and add them up (when turned on).

  • tiekubd
  • tiekubd
  • OFFLINE
  • Posts: 68
  • Thanks: 1
  • Karma: 0
8 years 1 month ago #285934 by tiekubd
What is the best way to do this:

A radio button field that assigns a value for the user when turned on
Perform a calculation based on all fields for the user and put value in integer field
e.g.

You get points for:
Has graduate degree = 20 points
Is married = 30 points
Has kids = 30 points

For user John:
o Has graduate degree = 20 points
o Is married = 30 points
Has kids = 30 points

Total score for John is
Has graduate degree + Is married
= 20 points + 30 points
= 50 points

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48454
  • Thanks: 8280
  • Karma: 1443
8 years 1 month ago - 8 years 1 month ago #285966 by krileon
Best way to do this is a code or query field. For example using CB Code Field you'd just substitute in the values then add them together. Example as follows.

Code:
return (int) '[cb_field1]' + (int) '[cb_field2]' + (int) '[cb_field3]';

It may look a bit strange, but substitutions need to be treated as strings and we want to typecast them to int for proper PHP math operation usage and to sanitize them.

If you absolutely need the total stored in the database you can use CB Auto Actions acting on the after user update trigger with a Field action to set an integer fields value. You'll need to enable format functions under parameters then use the math format function.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 8 years 1 month ago by krileon.

Please Log in or Create an account to join the conversation.

  • tiekubd
  • tiekubd
  • OFFLINE
  • Posts: 68
  • Thanks: 1
  • Karma: 0
8 years 1 month ago #285970 by tiekubd
Did you mean to say "code or query field"

Please Log in or Create an account to join the conversation.

  • tiekubd
  • tiekubd
  • OFFLINE
  • Posts: 68
  • Thanks: 1
  • Karma: 0
8 years 1 month ago #285973 by tiekubd
Are field1, field2, field3 radio buttons? (I want to turn the value on or off for each user)
How do I assign the fixed value (e.g. =20) to the radio button field?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48454
  • Thanks: 8280
  • Karma: 1443
8 years 1 month ago #285977 by krileon

Did you mean to say "code or query field"

Yes.

Are field1, field2, field3 radio buttons? (I want to turn the value on or off for each user)
How do I assign the fixed value (e.g. =20) to the radio button field?

Just set the value for that radio option to whatever points value you want. Otherwise you need to handle the points values in your custom PHP code based off the value of the field.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • tiekubd
  • tiekubd
  • OFFLINE
  • Posts: 68
  • Thanks: 1
  • Karma: 0
8 years 1 month ago #286017 by tiekubd
Don't see where to set a numerical value for a radio button field.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum