Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: form problem...

by Wonko the sane (Deacon)
on Feb 26, 2004 at 14:12 UTC ( #331993=note: print w/ replies, xml ) Need Help??


in reply to form problem...

Hello,

What you want to do is collect any previous movie selections
and pass them on to the form through hidden fields.

Something like this:

my $hidden_fields; $hidden_fields .= $cgi->hidden( $_, $in{$_} ) for ( grep { /dvdX/ } ke +ys %in );
Where %in is your hash if form vars retrieved from CGI->Vars.
Just print out the list of hidden fields as part of your form everytime.

Best Regards,
Wonko


Comment on Re: form problem...
Download Code
Re: Re: form problem...
by Nik on Feb 26, 2004 at 15:44 UTC
    i did not understand that. could you please modify the code i posted in your opinion to make it work?
    Thank you.
      my %in = $cgi_obj->Vars; # where $cgi_obj is whatever your CGI object +is. my $hidden_fields; # This for loop goes through each of the dvdX keys and creates an HTML + hidden field for them, appending each to the string of others. $hidden_fields .= $cgi->hidden( $_, $in{$_} ) for ( grep { /dvdX/ } ke +ys %in ); print start_form(-action=>'show.pl'); print table( {border=>1, -width=>'35%', -align=>'center', -style=>'bor +der: ridge lime; color: yellow; font-size: 20', -background=>'../data +/images/blue.jpg'}, Tr( {-align=>'center'}, td( 'Movie X' ), td( popup_menu(-name=>' +dvdX', -values=>[@tips] )), td( submit( 'Pick' ))), Tr( {-align=>'center'}, td( submit( 'Clear' )), td( submit( ' +Done' )))), br(), br(); print table( {border=>1, -width=>'35%', -align=>'center', -style=>'bor +der: ridge lime; color: yellow; font-size: 20', -background=>'../data +/images/blue.jpg'}, Tr( {-align=>'center'}, td( submit( 'Add' )), td( submit( 'Sh +ow' ))), Tr( {-align=>'center'}, td( submit( 'Modify' )), td( submit( 'De +lete' )))); # this is the string that contains all of the generated HTML hidden fi +elds we just made. print $hidden_fields; print end_form(), br(), br();
      If this still isnt making sense to you, then you should really take
      some time to go over to tutorials available on this site. As already siggested by others :)

      Best Regards,
      Wonko

        thanks man but it gives me an error!
        here is my code so far
        #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use DBI; use DBD::mysql; use Mail::Sendmail; $xronos = scalar(localtime(time + 7200)); $xronos =~ s/:\d{2} \d{4}//g; $ip = $ENV{'REMOTE_ADDR'}; @numbers = split (/\./,$ip); $address = pack ('C4', @numbers); $host = gethostbyaddr ($address, 2) || $ip; print header( -charset=>'iso-8859-7' ); print start_html( -title=>'Ψυχωφελή Πνευματικά Κείμενα!', -background= +>'../data/images/night.jpg' ); $db = ($ENV{'SERVER_NAME'} ne '50free.net') ? DBI->connect('DBI:mysql:nikos_db', 'root', '') : DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', 'macgyv +er') or print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0; print p( {-align=>'center'}, font( {-size=>5, -color=>'Cyan'}, "- Ηλεκ +τρονική Παραγγελία Ταινιών DVD -" )), br(); open(IN, '<movies.txt') or die $!; @tips = <IN>; close(IN); my %in = $cgi_obj->Vars; # where $cgi_obj is whatever your CGI objecti +s. my $hidden_fields; # This for loop goes through each of the dvdX keys and creates an HTML + hidden field for them, appending each to the string of others. $hidden_fields .= $cgi->hidden( $_, $in{$_} ) for ( grep { /dvdX/ } ke +ys %in ); print start_form(-action=>'show.pl'); print table( {border=>1, -width=>'35%', -align=>'center', -style=>'bor +der: ridge lime; color: yellow; font-size: 20', -background=>'../data +/images/blue.jpg'}, Tr( {-align=>'center'}, td( 'Movie X' ), td( popup_menu(-name=>' +dvdX', -values=>[@tips] )), td( submit( 'Pick' ))), Tr( {-align=>'center'}, td( submit( 'Clear' )), td( submit( ' +Done' )))), br(), br(); print table( {border=>1, -width=>'35%', -align=>'center', -style=>'bor +der: ridge lime; color: yellow; font-size: 20', -background=>'../data +/images/blue.jpg'}, Tr( {-align=>'center'}, td( submit( 'Add' )), td( submit( 'Sh +ow' ))), Tr( {-align=>'center'}, td( submit( 'Modify' )), td( submit( 'De +lete' )))); # this is the string that contains all of the generated HTML hidden fi +elds we just made. print $hidden_fields; print end_form(), br(), br(); $db->do( 'UPDATE counter SET visitor = visitor + 1' ); $st = $db->prepare( 'SELECT visitor FROM counter' ); $st->execute(); $row = $st->fetchrow_hashref; print p( {-align=>'center'}, submit( "$host" ), submit( "$xronos" ), s +ubmit( "$row->{visitor}" )); print p( {-align=>'center'}, a( {href=>'games.pl'}, img {src=>' +../data/images/games.gif'} ) ); print p( {-align=>'right'}, a( {href=>'../data/photos/'}, font( {-siz +e=>4, -color=>'Lime'}, 'Π' ) ) ); open(OUT, '>>../data/texts/log.txt') or die $!; print OUT $host, ' 'x(40-length($host)), '-> ', $xronos, '\n'; close(OUT); if ($ENV{'SERVER_NAME'} ne '50free.net') { exit 0; } %mail = ( To => 'nik0s@mycosmos.gr', From => '007@kyp.gr', Subject => 'Επισκέπτης από $host' ); sendmail(%mail) or die $Mail::Sendmail::error;
        the output is:
        Software error: Can't call method "Vars" on an undefined value at D:\web\cgi-bin\index +.pl line 30.
        well i think its because i didnt create a cgi object but i never do use cgi->new()
        and except of that how my order mysql table will have to be? how many fields do i have to set? i dont know the amount of the dvd that each if the user want to order so therefore i donw know how many myqll filed to create? i dont know how to organise this database.
        Can you help me please?
      No one will write it for you, read the CGI.pm info listed above, and also consider using Apache::Session, it will allow you to store a state in your CGI app -- which should help facilitate your shopping cart.


      -Waswas

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://331993]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-09-19 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (132 votes), past polls