cgi clearing a form

Discussion in 'Perl Misc' started by mcvallet@hotmail.com, Mar 23, 2006.

  1. Guest

    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
    , Mar 23, 2006
    #1
    1. Advertising

  2. wrote:
    > 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
    Mike Paolucci, Mar 23, 2006
    #2
    1. Advertising

  3. Guest

    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
    , Mar 23, 2006
    #3
  4. Guest

    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
    , Mar 23, 2006
    #4
  5. Guest

    wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Mar 23, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXM=?=

    clearing form/page cache

    =?Utf-8?B?Q2hyaXM=?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,135
    =?Utf-8?B?Q2hyaXM=?=
    Feb 14, 2005
  2. Alex

    Clearing textboxes in a form

    Alex, Apr 30, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    349
    Munsifali Rashid
    Apr 30, 2005
  3. praba kar
    Replies:
    0
    Views:
    316
    praba kar
    Jun 21, 2005
  4. Fredrik Lundh
    Replies:
    0
    Views:
    356
    Fredrik Lundh
    Jun 21, 2005
  5. Stefan Fischer
    Replies:
    2
    Views:
    262
    Stefan Fischer
    Feb 23, 2010
Loading...

Share This Page