Hello, I would like to create a questionnaire consisting of 6 checkboxes (1 max choice) with answers and their respective values as below,
1=Strongly disagree
2=Disagree
3=Neither agree nor disagree
4=Agree
5=Strongly Agree
When submitted the questionnaire will sum the values (points) and then generate one of the 3 messages, first for a sum of points in a range from 0 to 10, second in a range from 11 to 20 and third in a range from 21 to 30.
Currently I am lost and not really sure how to do that, appreciating any help. Thank you in advance.
Petr
1=Strongly disagree
2=Disagree
3=Neither agree nor disagree
4=Agree
5=Strongly Agree
When submitted the questionnaire will sum the values (points) and then generate one of the 3 messages, first for a sum of points in a range from 0 to 10, second in a range from 11 to 20 and third in a range from 21 to 30.
Currently I am lost and not really sure how to do that, appreciating any help. Thank you in advance.
Petr
Hi Petr,
Sorry but I don't understand your form setup - is this six sets of radio buttons?
Basically you can use an Event Switcher in the On Submit event to sum the results and display the corresponding message.
Bob
Sorry but I don't understand your form setup - is this six sets of radio buttons?
Basically you can use an Event Switcher in the On Submit event to sum the results and display the corresponding message.
Bob
Sorry, I was meaning 6 questions, and each question has 5 checkboxes with the answers and their respective values as stated above, see image.
I knew that the Event Switcher action is a potential option, however, I am not sure what exactly to put in the data provider and events to generate one of the three corresponding messages.
I am not an experienced programmer and thus I cannot solve this that easily.
Petr
[file=11391]questionnaire.png[/file]
I knew that the Event Switcher action is a potential option, however, I am not sure what exactly to put in the data provider and events to generate one of the three corresponding messages.
I am not an experienced programmer and thus I cannot solve this that easily.
Petr
[file=11391]questionnaire.png[/file]
{data.sum:questions}
Call your fields questions[#] replacing the # with either a number or unique name
Call your fields questions[#] replacing the # with either a number or unique name
Thank you, that worked very well! Although now that I have the sum of the values, how to implement the number range in the event switcher?
Petr
Petr
Ok use a PHP block instead, array sum $this->data($questions). Use if / then / else, return some value and use {var:phpblockname} in your event switch data source.
Could you please provide an example of the code before the 'if' function? I tried many times but always ended with error, otherwise returning the assigned value for the event switcher won't be a problem.
$total = array_sum($this->data("questions"));
if($total < 20) { return 1; }
else if($total < 40) { return 2; }
else if($total < 50) { return 3; }
if($total < 20) { return 1; }
else if($total < 40) { return 2; }
else if($total < 50) { return 3; }
Thank you for your fast reply! This is what I have had already tried for the firs time but it still ended with error. Any other possible suggestions?
I suggest you be clearer about what you mean by "error"
After submitting the form returns
even without showing the debug.
0 syntax error, unexpected 'if' (T_IF)
even without showing the debug.
Did you copy and paste from the forum? If so delete Everything and type out manualy.
The form does not end with error now, but it doesn't sum correctly, I used this code
and it always keep returning var=1 even when the sum of values is for example 24.
$total = array_sum($this->data($questions));
if($total >= 0 && $total <= 10) { return "1"; }
elseif ($total >= 11 && $total <=20) { return "2"; }
elseif ($total >= 21 && $total <=30) { return "3"; }
and it always keep returning var=1 even when the sum of values is for example 24.
Post your debug
Array ( [option] => com_chronoforms6 [cont] => manager [chronoform] => o3-questionnaire [event] => submit [questions] => Array ( [1] => 4 [2] => 4 [3] => 4 [4] => 4 [5] => 4 [6] => 4 ) [button16] => )
Array ( [data] => Array ( [returned] => 1 [var] => 1 ) )
Are you using the correct PHP block, or the incorrect custom code block?
Yes, I use the PHP block, here is a pic of the functions setup.[file=11432]setup.png[/file]
Okay, I sorted it out. I falsely called the array in the array_sum. It is working now. Thank you for your help!
What do the settings of the Event Switcher look like
Coolbeans. Mark http://www.chronoengine.com/forums/posts/t106576/p382910#p382910 as the answer if you can thanks, or pick another one as the answer.
This topic is locked and no more replies can be posted.