Solved

how do I post a feedback message on a drupal form

Posted on 2010-08-12
10
486 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
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!

 

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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

679 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