Hide checkbox values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
al3xandar
Forum Newbie
Posts: 15
Joined: Tue Dec 16, 2008 3:05 pm

Hide checkbox values

Post by al3xandar »

Hello there,
I'm new in PHP programming, so I quess what I'm about to ask is completely noob question... :oops:
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?! :dubious:
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Hide checkbox values

Post 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.
al3xandar
Forum Newbie
Posts: 15
Joined: Tue Dec 16, 2008 3:05 pm

Re: Hide checkbox values

Post 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!!!
:mrgreen:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Hide checkbox values

Post 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).
al3xandar
Forum Newbie
Posts: 15
Joined: Tue Dec 16, 2008 3:05 pm

Re: Hide checkbox values

Post 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!!
:crazy:

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...!?!
:wink:
Post Reply