Solved

how do I post a feedback message on a drupal form

Posted on 2010-08-12
10
477 Views
Last Modified: 2012-05-10
I have a webform where I want to add up the score for the selections made on the form, e.g. the user gets from 1 to 5 points for each answer, and give the user a message based on his score.  I thought about using a markup field on the webform, but it seems that I cannot set the value of a markup field.  

I set up the webform and I know that I can write the code in the 'additional processing' for the form.  

How do I access the field values to add up the score and more importantly,
How can I display the feedback after the user hits submit.  I want to give them their score and a message like 'great job' or 'needs improvement'.
0
Comment
Question by:d2fox
  • 5
  • 4
10 Comments
 
LVL 17

Expert Comment

by:Thomas4019
ID: 33425453
I've never used webform before, I'm more a fan of CCK myself, http://drupal.org/project/cck.

I know with CCK and Rules you could process a submission and deliver conditional messages.
http://drupal.org/project/rules
0
 

Author Comment

by:d2fox
ID: 33425516
I don't know how to set up a form in cck.  Are you saying it won't work well in webform?
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 33425524
What exactly are you trying to do, CCK is definitely more powerful that webform, but if you are trying to collect data in a survey like fashion the webform is easier.

Rules could work with webform but not easily, http://drupal.org/node/474644.

Again, if you explain what you are trying to do as a whole, i can tell you what way would be easiest.
0
 

Author Comment

by:d2fox
ID: 33425559
I have 10 questions that the user has to answer 'yes / maybe / no'.  For each of the 'yes' answers, they get 1 point.  5 points gets them a 'you are doing ok' result, 8 or more gets them a 'great job', less than 5 gets them a 'you need to work on improving'.


That's it.  I have the form, need to figure out the code.

Thank you.
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 33425589
sounds like either CCK or webform will work great.

If you're going to do any PHP coding in Drupal, you will want the module Devel installed so that you can call the function dpm(). See this guide, http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-development-tips-list-all-available-variables-and-backtrace-a-page/.

Once you find out how to access the fields (which the above link should show you how), then you can use drupal_set_message() to show a box on the next page with a configurable message, http://api.drupal.org/api/function/drupal_set_message/6.
0
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

 

Author Comment

by:d2fox
ID: 33428543
so I can set the message, but it shows with the normal form submission and doesn't stand out.  It's in a yellow box with the message 'thank you, your sumission has been received' below it.  How can I remove that message and make mine more prominent?
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 33431560
Cool, looking at this,http://api.drupal.org/api/function/drupal_set_message/6, there's an optional second parameter where you can set the type. If you set it to 'warning'  or 'error' it should stand out more.

Also look at this post, http://drupal.org/node/214389.

It looks like calling drupal_get_messages() will clear any messages that have been set.

Good luck,
Thomas Hansen
0
 

Author Comment

by:d2fox
ID: 33434371
hmmm, can't seem to get rid of the system generated messages.  I still get my message, then

Thank you, your submission has been received.
You have already submitted this form. View your previous submissions.

I put this in the 'additional processing':  

drupal_get_messages();
drupal_set_message('This is my message.','warning');
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 33434413
That must mean Webform is displaying that message after is displaying it's message after your custom PHP code.

Well, a hackish way of solving this might be to use string overrides, http://drupal.org/project/stringoverrides,  to replace that text, "Thank you, your submission has been received." with nothing.

Or if you want to be REALLY hackish delete line 2005 from webform.module in the webform folder. This get's annoyting because you'd have to re-delete that line everytime you upgrade.

It's actually not that hard to make forms with a custom module using the forms api, http://drupal.org/node/751826. You could do that instead of webform which would give you near infinite flexibility.
0
 
LVL 2

Accepted Solution

by:
TheChemic earned 500 total points
ID: 33492866
If this were my project...

I would create separate pages/nodes for each message.

Node: Great Job
           You did really good, bla bla bla

Node: You did okay
           Sounds like you're an average person, bla bla bla

Node: You could use some improvement
          Dude, you kinda sucked man, bla bla bla

etc..

Then, I would use rules to forward the user to each individual page/node based on their score.  Since this would be a FULL PAGE, it would not appear tiny and you could customize it's appearance in any way you like.  I often use rules and custom landing pages depending on user actions.  It works great for me.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

706 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

18 Experts available now in Live!

Get 1:1 Help Now