Hidden overload and It is a better ways to save to Mysql, it is?

P

phal

Dear all perlist

I use hidden field to pass data from one step to the other step, for
exam, if user choose to have 50 information to retrieve.
And according to the order, they will allow to jump from one records to
the other without any problem, they will able to go to the 48 record
and jump back to 1 record. In each step user allow to edit the record,
such as change the date or choose the alternative choice which as
check_box or radio_box. During each jump and any make change, the
record (jump or change record) will keep in the hidden filed untill the
user click submit which is display only after the 50 records. But the
problem is when user jump from one record to the other record, the
hidden filed record the duplicate information about each record that
have been visited several time by the user. And if the hidden become
larger, the program will run slow and sometime hung. I wish to save
each step into database, but it isn't a good idea, because the record
will not allow to save change during each jump, the record must be
saved only after sumbit button is click.

Any exper perlist give me some commond regard to the problem above?

Thank
Phal
 
R

Ron Savage

On Thu, 6 Oct 2005 16:51:34 +1000, phal wrote:

Hi Phal
I use hidden field to pass data from one step to the other step,

You have not described the problem well.

I /guess/ you are talking about hidden fields in HTML.

In that case, you are strongly advised to start all of using:

CGI::Application
HTML::Template
CGI::Session, or even better, CGI::Application::plugin::Session

where CGI::Session can be used to store the data so that you do not need touse
hidden fields, apart for the 1 hidden field which holds the session id.

Note: Some people use cookies to store the session id. I prefer hiddenfields.
 
X

xhoster

phal said:
Dear all perlist

I use hidden field to pass data from one step to the other step, for
exam, if user choose to have 50 information to retrieve.
And according to the order, they will allow to jump from one records to
the other without any problem, they will able to go to the 48 record
and jump back to 1 record. In each step user allow to edit the record,
such as change the date or choose the alternative choice which as
check_box or radio_box. During each jump and any make change, the
record (jump or change record) will keep in the hidden filed untill the
user click submit which is display only after the 50 records. But the
problem is when user jump from one record to the other record, the
hidden filed record the duplicate information about each record that
have been visited several time by the user.

If you don't want to store all of that replicate information, then don't
have it store all of that replicate information. Identify the small part
of your code that is causing this replication, and either fix it or post it
here so we can help you with it.

And if the hidden become
larger, the program will run slow and sometime hung.

Just how large is it getting?
I wish to save
each step into database, but it isn't a good idea, because the record
will not allow to save change during each jump, the record must be
saved only after sumbit button is click.

You could save what is in the hidden fields into a database (by which I do
not mean to update the records in the original table(s), but rather use a
different table which holds the information that the hidden fields
currently holds). Then you could just pass a much smaller key to that data
back and forth between the web browser and cgi server, rather than the data
itself. However, since your current hidden fields seem to be leaking, a
simple change would mean your database-stored data would also be leaking,
so your root problem would not be solved.


Xho
 
P

phal

Hi all


The below code has problem when I want to double click or backward or
forward several time the hidden field record the duplication
information, and this is not what I want, and when the duplicate
information is too much, it getting slower and slower then sometime
hang the PC as well.


I do not use Cookie for storage.


Thank
Phal


----------------------------------------------------------


if(param('START_'))
{
$print_question=TR(th(submit(-name=>'GOTO',-value=>'Next'),

hidden(-name=>'ID',-value=>$examid),hidden(-name=>'TOTAL_DISPLAY',-value=>$­select_display),

hidden(-name=>'POP',-value=>$popup_question),

popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],
-default=>1),
submit(-name=>'GOTO',-value=>'Go')));

$print_question.=&Generate_Question(\@{$questions{1}},\@ALL_QUESTIONS,\1,\'­None

~') ;
if(scalar (@{$questions{1}}) > 4) {
$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),popup_menu(-nam­e=>'GOTOQ',-value=>[1..$popup_question,'Submit'],-default=>1),submit(-name=­>'GOTO',-value=>'Go')));



}


&Display_Question($print_question);

}


#----------------------------------------------------------
$popup_question=param('POP');
my @popup_;

for(my $n=1; $n<= $popup_question; $n++){
push @popup_,$n;
push @popup_, 'Submit' if $n == $popup_question;


}


my $total_display=param('TOTAL_DISPLAY');
my $total_x=($per_display*$total_display)+$less_question ;

my %question_answers;
my $print_hidden;
#----------------------------------------------------------
for(my $x=1; $x<=$total; $x++)
{
my $count_q=$x.'Q';
my $question_id=param($count_q); # get the question ID
my $question_answer;
my $question_type;


my $check_box=$question_id.'CHECK';
my $radio_box=$question_id.'RADIO';


if(param($check_box))
{
foreach(param($check_box)){
$question_answer.=$_;
}


$question_type=$check_box;
}
else{
$question_answer=param($radio_box);
$question_type=$radio_box;
}


if($question_answer ne "")
{
print
hidden(-name=>$count_q,-value=>$question_id),hidden(-name=>$question_type,-­value=>$question_answer);



}



}


#-----------------------------------------------------------
for( my $xp=0; $xp < @popup_; $xp++)
{
if(param('GOTOQ') eq "$popup_[$xp]")
{
my $select=param('TOTAL_DISPLAY'); # total question to
display in
each screen
my $count=0; # count the
questions
$count=1 if($popup_[$xp] =~/1/); # when the first
question count
start from 0
$count=1+$select*$popup_[$xp]-$select if($popup_[$xp]
1); # when
not the first question count


$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),

hidden(-name=>'ID',-value=>$examid),hidden(-name=>'TOTAL_DISPLAY',-value=>$­select_display),hidden(-name=>'POP',-value=>$popup_question),

hidden(-name=>'CURRENT',-value=>$popup_[$xp]),

popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],
-default=>$popup_[$xp]),
submit(-name=>$popup_[$xp],-value=>'Go')));

$print_question.=&Generate_Question(\@{$questions{$popup_[$xp]}},\@ALL_QUES­TIONS,\$count,\'None

~ ') ;
if(scalar (@{$questions{$popup_[$xp]}}) > 4) {
$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),popup_menu(-nam­e=>'GOTOQ',-value=>[1..$popup_question,'Submit'],-default=>$popup_[$xp]),su­bmit(-name=>'GOTO',-value=>'Go')))

; }
&Display_Question($print_question);
}


}


#-------------------------------------------------------------
if(param('GOTO') eq 'Nextxx')
{

my $current=param('CURRENT');
my $select_display=param('TOTAL_DISPLAY'); # total question to
display
in each screen
my $examid=param('ID');
$popup_question=param('POP');


$current+=1;
print "$current $popup_question";


if($current < $popup_question)
{
my $count=0; # count the
questions
$count=1 if($current =~/1/); # when the first
question count start
from 0
$count=1+$select_display*$current-$select_display
if($current >
1); # when not the first question count



$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),

hidden(-name=>'ID',-value=>$examid),hidden(-name=>'TOTAL_DISPLAY',-value=>$­select_display),hidden(-name=>'POP',-value=>$popup_question),

hidden(-name=>'CURRENT',-value=>$count),

popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],
-default=>$count),
submit(-name=>$count,-value=>'Go')));

$print_question.=&Generate_Question(\@{$questions{$count}},\@ALL_QUESTIONS,­\$count,\'None

~ ') ;
if(scalar (@{$questions{$current}}) > 4) {
$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),popup_menu(-nam­e=>'GOTOQ',-value=>[1..$popup_question,'Submit'],-default=>$current),submit­(-name=>'GOTO',-value=>'Go')))

; }
&Display_Question($print_question);
}


}


#-------------------------------------------------------------

if(param('GOTOQ') eq 'Submit')
{
my (%temp,@data,$question_id,$count_q,$question_answer);
#--------------------------------------------------------------------------­--------

for(my $x=1; $x<=$total; $x++)
{
$count_q=$x.'Q';
$question_id=param($count_q); # get the question ID
$question_answer='RtExt';


my $check_box=$question_id.'CHECK';
my $radio_box=$question_id.'RADIO';


if(param($check_box))
{

foreach(param($check_box)){$question_answer.=$_.' MIXX ';}
}
else
{
$question_answer=param($radio_box);
}


print "$question_id=$question_answer <br>";
}



}


print end_form(),end_html();
###########################################################################­###

sub Generate_Question
{
my ($total_)=shift(@_);
my ($aoh)=shift(@_);
my ($tcount)=shift(@_);
my ($value_)=shift(@_);

my @total=@$total_;
my @AOH=@$aoh;
my $count=$$tcount;
my $value=$$value_;


my $print_question;
my %label_hash;
my $label_count=1;


foreach my $hash(@AOH)
{
for my $k (@total)
{
if($k)
{ foreach my $_ik(sort keys
%{$hash->{$k}})
{
if($_ik eq 'a_question'){



$print_question.=TR(th(hidden(-name=>$count.'Q',-value=>$k)));



$print_question.=TR(th({-align=>'left',-colspan=>2},font({-size=>$_EQ_body}­,$count,

". ",$hash->{$k}{$_ik})));
$count+=1;
}
if($_ik eq 'b_description'){

$print_question.=TR(th({-align=>'left'},font({-size=>$_EQ_body},"(",$hash->­{$k}{$_ik},")")));

}
if($_ik eq 'c_answer') {
$label_count=1;
for my
$in(0..$#{$hash->{$k}{$_ik}})
{ # print " IN
SIDE $label_count ";

$label_hash{$label_count}=$hash->{$k}{$_ik}[$in];
$label_count++;



}
# print "NUMBER
$label_count";
my @size=keys %label_hash;
# print "dddddddddddd @size
dddddddddd";


$print_question.=TR(th({-align=>'left'},
font({-size=>$_EQ_body},

checkbox_group(-name=>$k.'CHECK',-values=>[1..$#size+1],-linebreak=>'true',­-labels=>\%label_hash,-default=>$value),hidden(-name=>$k.'TYPE',-value=>'CH­ECK_GROUP'))))

if ($hash->{$k}{'1_question_type'} =~/check_group/gi);

$print_question.=TR(th({-align=>'left'}, font({-size=>$_EQ_body},

radio_group(-name=>$k.'RADIO',-values=>[1..$#size+1],-linebreak=>'true',,-l­abels=>\%label_hash,-default=>$value),hidden(-name=>$k.'TYPE',-value=>'RADI­O_GROUP'))))

if ( $hash->{$k}{'1_question_type'} =~/radio_group/gi);
}
}
}


}


}
return $print_question;



}
 
X

xhoster

phal said:
Hi all

The below code has problem when I want to double click or backward or
forward several time the hidden field record the duplication
information, and this is not what I want, and when the duplicate
information is too much, it getting slower and slower then sometime
hang the PC as well.

Your code is hideous. There is no way I'm going to sort through that
overly long and malformatted mess. If you re-wrote the code so that it
is legibile, perhaps you could find the problem yourself. It also seems
to have a lot of needless variables representing things like lengths of
arrays. Arrays know how long they are.

You could at least tell us the name of the specific hidden field that is
getting duplicated.

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,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top