Solved

how can i get my drupal form radio buttons selected

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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

622 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