Solved

how can i get my drupal form radio buttons selected

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ajax and PHP 9 53
assigning javascript variable to php variable 8 33
JSON decode 5 14
php output utf-8 problem 6 12
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

685 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