• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1065
  • Last Modified:

how can i get my drupal form radio buttons selected

I have a form with a set of questions with radio button answers set up 'Yes', 'No', and 'Don't know'.  I want to count the # of Yes's that the user submitted.

When I use the following code, I always get a count of all my questions, regardless of what I answer.  

$count = 0;
foreach ($form_state['values']['submitted_tree'] as $key => $val) {
  if ($val="Yes") {

What am i doing wrong?
1 Solution
There are some good techniques for debugging problems like this.

A good thing to have is develed installed and access to it's dpm() function. It is like var_export() or var_dump() but much better. You can pass dpm and object and then it will show the object on the page in a very readable format. So here's what you should do.

1. Make sure devel is installed.

2. Add this code


3. Look over the output and see where you are making your mistake.
Ray PaseurCommented:
Use a single equal sign as an assignment operator
Use a double equal sign as a comparison operator.

HTH, ~Ray
$count = 0;
foreach ($form_state['values']['submitted_tree'] as $key => $val) 
    if ($val == "Yes") 

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now