Hello,
I have a 10 question form in multi-page view. (test_page1, test_page2) and would like the user to view their test results after submission. ie. Test Score: 80%
I'm attempting to this using PHP & placing the code in the "On Submit code - Section" of CF
I am able to create a simple loop statement but when referencing the form variables within the the PHP tags, I get a blank screen after submission. Removing {radio0} fixes the problem, and allows me to submit the form. I take it the syntax is incorrect.
---------my-code---------
<p class="style2">Congratulations, <strong>{first_name} {last_name}</strong> you have succesfully completed <strong>{testname}</strong>, Test.
Below are your score results.
<?php
for ($i=1; $i<=10; $i++)
{
if {radio0} <> 'true' echo "incorrect answer";
}
?>
---------code----------
What would be the simplest way to do this?
To allow the user to view their test results/grade?
Thank You
-Joe
I have a 10 question form in multi-page view. (test_page1, test_page2) and would like the user to view their test results after submission. ie. Test Score: 80%
I'm attempting to this using PHP & placing the code in the "On Submit code - Section" of CF
I am able to create a simple loop statement but when referencing the form variables within the the PHP tags, I get a blank screen after submission. Removing {radio0} fixes the problem, and allows me to submit the form. I take it the syntax is incorrect.
---------my-code---------
<p class="style2">Congratulations, <strong>{first_name} {last_name}</strong> you have succesfully completed <strong>{testname}</strong>, Test.
Below are your score results.
<?php
for ($i=1; $i<=10; $i++)
{
if {radio0} <> 'true' echo "incorrect answer";
}
?>
---------code----------
What would be the simplest way to do this?
To allow the user to view their test results/grade?
Thank You
-Joe
Hi someguy2k,
I think the 'if' syntax is wrong. This line should have extra ()
Bob
I think the 'if' syntax is wrong. This line should have extra ()
if ( {radio0} <> 'true' ) echo "incorrect answer";
but it would be even better to spell it out$radio0 = JRequest::getString('radio0', 'false', 'post');
if ( $radio0 != 'true' ) {
. . .
Bob
Bob,
Thank You very much for your prompt reply...
[quote="GreyHead"]
using the cf form variables: radio0, radio1, radio2, radio3, etc...gives me an error when submitting the form
using the this code, I am able to submit the form but echo $radio0 doesn't display anything...
It seems I can't use any cf Vars within php tags. i.e echo {radi0}; will not work. Ultimately what I want is to compare the submitted info with an answer key.
Please let me know if this is beyond this level of support and/or where I can post for further/paid help.
Thanks again.
Thank You very much for your prompt reply...
[quote="GreyHead"]
if ( {radio0} <> 'true' ) echo "incorrect answer";
using the cf form variables: radio0, radio1, radio2, radio3, etc...gives me an error when submitting the form
$radio0 = JRequest::getString('radio0', 'false', 'post');
if ( $radio0 != 'true' ) {
. . .
using the this code, I am able to submit the form but echo $radio0 doesn't display anything...
It seems I can't use any cf Vars within php tags. i.e echo {radi0}; will not work. Ultimately what I want is to compare the submitted info with an answer key.
Please let me know if this is beyond this level of support and/or where I can post for further/paid help.
Thanks again.
Hi someguy2k,
Please turn on debug for the form and them submit it. In the error messages with a blue background you should see a copy of the $_POST array which has all the results from the form. Please post that here so the we can see the raw data you are working with.
If echo $radio0 doesn't display anything then it's probably an array - try print_r ($radio0); instead.
Also in the first code you posted you have a loop for ( $i =1,. . . but you aren;t using $i inside the loop.
I suspect that you need to get help from someone with a bit more PHP knoweldge.
Bob
Please turn on debug for the form and them submit it. In the error messages with a blue background you should see a copy of the $_POST array which has all the results from the form. Please post that here so the we can see the raw data you are working with.
If echo $radio0 doesn't display anything then it's probably an array - try print_r ($radio0); instead.
Also in the first code you posted you have a loop for ( $i =1,. . . but you aren;t using $i inside the loop.
I suspect that you need to get help from someone with a bit more PHP knoweldge.
Bob
I suspect that you need to get help from someone with a bit more PHP knoweldge.
Bob
Hi Bob,
You were right on the money with everything. I'm learning PHP and didn't know how to loop through the $_POST array properly. Instead of replying back with more questions, I spent the ALL day researching and reading about Arrarys. Again, thank you for the support on this issue.
Below is the code of the project excluding the mySQL connection/declarations...
for ($i=0; $i<$num; $i++)
{
foreach (array_keys($_POST) as $key)
{
$$key = $_POST[$key];
if ($key == 'radio0' || $key == 'radio1' || $key == 'radio2' || $key == 'radio3' || $key == 'radio4' || $key == 'radio5' || $key == 'radio6' || $key == 'radio7' || $key == 'radio8' || $key == 'radio9')
{
if (mysql_field_name($result,$i) == $key)
{
if (mysql_result($result,0,$i) == ${$key})
{
$correct++;
}
if (mysql_result($result,0,$i) != ${$key})
{
$incorrect++;
echo "<font color='red'><b>Question # " . $question . " was incorrect";
print "</font></b><br> Selected Answer: ${$key}<br />";
echo "Correct Answer: " . mysql_result($result,0,$i);
}
}
}
}
$question++;
echo "<p>";
}
$score = $correct * 10;
echo "<br><br />";
echo "<p><b><font size='3'>Test Score: <font color='red' size='3'></b>" . $score . "%</font>";
-joe
This topic is locked and no more replies can be posted.