Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how can i get my drupal form radio buttons selected

Posted on 2010-08-27
2
Medium Priority
?
1,043 Views
Last Modified: 2012-05-10
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") {
    $count++;
  }
}

What am i doing wrong?
0
Comment
Question by:d2fox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Expert Comment

by:Thomas4019
ID: 33548142
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

dpm($form_state);

3. Look over the output and see where you are making your mistake.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 33552385
Use a single equal sign as an assignment operator
Use a double equal sign as a comparison operator.
http://php.net/manual/en/language.operators.comparison.php

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

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question