cgi - Hidden Field Manipulation in Perl -


i'm trying write multi question survey in perl displays 1 question @ time "previous" , "next" button. need read questions file, haven't gotten far yet hard coding them in now.

part of assignment requirements must use cgi, cannot print html directly.

currently have script printing out first question, along 2 submit buttons, 1 labeled 'next' , other 'previous'.

print $form->submit(-name=>'question', -value=>'next');
print $form->submit(-name=>'question', -value=>'previous');

i have hidden field:

print $form->hidden(-name=>'hidden', -value=> $currentq);

my idea once next clicked, increment (or decrement, if previous clicked) $currentq script knows question on.

the problem i'm having manipulating hidden field once button pushed. have:

my $direction = $form->param( 'question' ) || '';
if ($direction eq 'next'){ $currentq++; }

along print statement print $currentq. in other words, should print higher number each time click next, remain @ 1(this test functionality, once working have figure out how implement print correct question).

hopefully description makes sense, if need more details please let me know. i'm stuck on one, appreciated, in advance!

you have inconsistency; naming hidden field "hidden", getting value parameter "question". don't know if present in actual code.

one gotcha using cgi value passed input-field producing methods default value; value supplied request takes precedence:

use cgi; $form = cgi->new("hidden=41"); print $form->hidden(-name=>'hidden', -value=>42); 

prints

<input type="hidden" name="hidden" value="41"  /> 

to change this, either need supply -override parameter:

print $form->hidden(-name=>'hidden', -value=>42, -override=>1); 

or change stored value of parameter:

$form->param('hidden',42); print $form->hidden(-name=>'hidden', -value=>42); 

make sure "if next, increment" logic executed before call hidden method generate html.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -