Solved

how can i get my drupal form radio buttons selected

Posted on 2010-08-27
2
1,015 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
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 108

Accepted Solution

by:
Ray Paseur earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now