Page 1 of 1
Hide checkbox values
Posted: Tue Dec 16, 2008 3:18 pm
by al3xandar
Hello there,
I'm new in PHP programming, so I quess what I'm about to ask is completely noob question...
How can I hide checkbox values? Is it possible to do such thing in the first place?
I'm about to post a simple questionnaire to several hundred respondents, and I'm trying to hide the checkbox values, so they cannot "brake" the scoring code...
So... is it possible, or is it NOT?!

Re: Hide checkbox values
Posted: Tue Dec 16, 2008 4:57 pm
by watson516
What do you mean by 'hiding the check box value'? Do you want to hide the source? I don't think thats possible.
I don't really see how having a 'visible' check box value could brake your script. Unless you have something like +1, +2, +3, etc for the values. In that case, you might want to change it to a less obvious value and just have the script do the checking of the answers.
Re: Hide checkbox values
Posted: Tue Dec 16, 2008 5:31 pm
by al3xandar
Yup... that's what I thought!
I can assign some not-so-obvious-value for checkbox... and then to create a function that will evaluate the questionnaire!
Thanx!!!

Re: Hide checkbox values
Posted: Tue Dec 16, 2008 9:56 pm
by John Cartwright
I still wouldn't leave any room for cheating. What exactly are the values you are trying to hide?
This is a very general topic, but typically the server side language would perform the value lookup and calculation (based on the users permission).
Re: Hide checkbox values
Posted: Wed Dec 17, 2008 2:34 am
by al3xandar
OK, I'm posting a code... here goes:
<?
$itemName = array("",
"Question A",
"Question B",
"Question C",
"Question D",
"Question E",
"Question F",
"Question G",
"Question H",
"Question I",
"Question J");
HERE;
printForm();
evaluate();
postTest();
function printForm(){
global $itemName;
for($i = 1; $i <= 10; $i++) {
print "<b>$i. $itemName[$i] </b>";
print <<<HERE
<input type = "checkbox"
name = "itemNo[$i]"
value = "a">
<br>\n
HERE;
} // end for loop
} // end printForm
function evaluate() {
if($itemNo[$i] == "a"){
$iat[$i] = 1;
} // end if
$score = $i * $iat[$i];
} // end evaluate
and, of course, the postTest function will post the $score value to result.php page... I'm about to write it, and thinking about something like this (I might have messed something up in this one):
function postTest() {
global $score;
print <<<HERE
<input type = "hidden"
name = "hdnSubmit"
value = "$score">
<br><br>
<input type = "submit"
value = "Submit test">
<br><br>
<input type = "reset"
value = "Reset answers">
HERE;
} // end postTest
?>
I tried to "hide" the values by setting the checkbox value as "a", then "recoding" that value to 1 on the score variable. I quess there has to be more efficiant & ellegant way to do this, so, pls, let me know!!
And, yup, "Question A to I" are just here as an example... I certainly do not intend to post the real on forum... Who knows...!?!
