cgi clearing a form

M

mcvallet

Hi,
I am writing a dynamical quiz and and once this quiz is submitted, I
display the answers. the problem is that when I submit the form without
answering the question in the display, I still get 'answers' that where
submitted previously.
I tried several thing like :
in the writing the form
#create the new writer
my $cgiWriter = new CGI("");
#reset any possible values kept previously
$cgiWriter->delete_all();

in correcting the form :
#create the new writer
my $cgiWriter = new CGI("");
some code
foreach my $p ( param() ) {

$form{$p} = param($p);

}

$cgiWriter->delete_all();
but it does not seem to work. could someone help me,
thanks
 
M

Mike Paolucci

Hi,
I am writing a dynamical quiz and and once this quiz is submitted, I
display the answers. the problem is that when I submit the form without
answering the question in the display, I still get 'answers' that where
submitted previously.
I tried several thing like :
in the writing the form
#create the new writer
my $cgiWriter = new CGI("");
#reset any possible values kept previously
$cgiWriter->delete_all();
in correcting the form :
#create the new writer
my $cgiWriter = new CGI("");
some code
foreach my $p ( param() ) {
$form{$p} = param($p);

$cgiWriter->delete_all();
but it does not seem to work. could someone help me,
thanks

You haven't said explicitly, but I suspect these "answers" are being
input through an HTML textarea control. If this is the case then you
should do something like this:

my $reset = <set $reset based on some criteria for clearing the form>;

then later on in your code ...

textarea( -name => 'answer10',
-value => param( 'answer10' ),
-override => $reset,
-default => '',
-rows => 10,
-columns => 80 )

If -override is "true" then the -default value is used
(regardless of the value in -value).


I haven't looked at any other HTML controls in CGI.pm, but I
suspect that the other controls may have something similar.

HTH
 
M

mcvallet

thank, it work very well for the texfields and textareas but i still
have a problem with my radio buttons :
#declaration of the variables are at the beginning of my code

if ($answerGiven =~ m/$answerIndex/i){#if the radio button was checked
before than check it again
print $cgiWriter->radio_group(
-name => "$name" #name of the group
,-values => \%labels #list of values for the radio buttons
(two values only value and the "seen value"
,-linebreak => 'true' #puts line breaks between the buttons,
creating a vertical list
,-checked => "" #no default value is selected
,-readonly => ""
, -override => 1


);
}else{#if the radio buton was not checked before than don't check it
print $cgiWriter->radio_group(
-name => "test$name" #name of the group
,-values => \%labels, #list of values for the radio buttons
,-linebreak => 'true' #puts line breaks between the buttons,
creating a vertical list
,-default => "" #no default value is selected
,-readonly => ""
, -override => 1
);
}
and second question that I would like to know you can readonly on
textfield/area but it does not seem to work with radio buttons is there
a way to do it ?
thanks again,
mc
 
M

mcvallet

never mind, it works also with the radio buttons, this was my problem :
$answerGiven =~ m/$answerIndex/i instead of writing $answerIndex =~
m/$answerGiven/i
thank you ,
mc
 
X

xhoster

Hi,
I am writing a dynamical quiz and and once this quiz is submitted, I
display the answers. the problem is that when I submit the form without
answering the question in the display, I still get 'answers' that where
submitted previously.

perhaps:
use CGI qw(-nosticky);
?

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top