develooper Front page | perl.beginners | Postings from April 2002

Hidden fields and Perl

Thread Next
April 29, 2002 14:59
Hidden fields and Perl
Message ID:
What I am trying to do is develop a manager for  albums and songlist. I have
gotten most of it done. However, here I am having problems with Perl keeping
the values set via a form hidden field.  --

this is how the link looks when the script is called..

the file is what opendir uses to obtain the records..  etc etc..

here are the hidden fields that get their values once the &parseform sub is

print "<input type=\"hidden\" name=\"name\" value\"$nameHead\">";
print "<input type=\"hidden\" name=\"file\" value\"$filename\">";
print "<input type=\"hidden\" name=\"artists\" value\"$Artist\">";

this is what gets returned when I do a get after I try to delete the data

What I would expect as a return value is


this way it still reads from the same file.

Let me know thanks..


#written by Ray Alba - link manager for#file called group_view.cgi
#written Feb 19,2002

use CGI;

my (


$path = "your path"; # has to change when we move the site to server..
$fields = 5;                       # Number of fields in each record
$results = 1000;               # maximum number of results to display

print "Content-type: text/html\n\n";

#must do to check etc..

if($nameGroup ne "") {
 $filename = "$nameGroup";      # The database text file


print "<html><head><title>DELETE EM</title>";
print "<script language=JavaScript>\n\n \n\n";
print "function confirmME() { confirm(\"Are you sure you want to delete this
print "</head><body bgcolor=ffffff>";
print "<form  method=\"GET\" action=\"song_admin.cgi\" name=\"delLink\">\n";

print "<table border=1 width=90%>";
print "<tr>";

print "<td height=40 colspan=5 align=left valign=bottom>
<blockquote><h3>$nameHead - $Artist</h3></blockquote>

print "<input type=\"hidden\" name=\"name\" value\"$nameHead\">";
print "<input type=\"hidden\" name=\"file\" value\"$filename\">";
print "<input type=\"hidden\" name=\"artists\" value\"$Artist\">";

$count =0;

while ((@line = &read_file(FILE1)) && ($count < $results)) {

 @nline = @line;


#read lines in as an array
#@nline = sort {$a cmp $b} @nline;
#sort lines
 # how data is stored song|songtime|theme|style|lyrics|realname|mpname

for ($i =0; $i < scalar(@nline); $i++) {
  @tab =  split(/\s*\|\s*/,$nline[$i],$fields);
  $song = $tab[0];
  $songtime = $tab[1];
  $theme = $tab[2];
  $style = $tab[3];
  $lyrics = $tab[4];
  $realname = $tab[5];
  $mpname = $tab[6];
  $vocals = $tab[7];

#put here to show array count to determine record id

print "</td></tr></table><p><p><p><p align=center> <input type=submit
name=\"delete\" value=\"delete\"

if($count ==0) {

sub print_file {
  $newCount = $i + 1;

  print "<tr>\n
  <td colspan=5 align=left valign=top  ><input type=\"radio\" name=\"item\"
value=\"$newCount\" onClick=\"dimDelOff()\"> delete   &lt;<a
  <table width=90% cellspacing=0 cellpadding=5 border=0>\n
  <tr bgcolor=\"#abcdef\">\n
  <td align=right valign=top width=35><div type=\"text/css\"
style=\"font-size: 16px;\"><b>$newCount.</b> </div></td>\n
  <td align=left valign=top><div type=\"text/css\" style=\"font-size:
  <td align=right valign=top>$songtime</td></tr>\n
  <td valign=top align=left>";

  if($vocals) {
   print "Lead Vocals: " . $vocals . "<br>";

  print "Style:  $style<br>Theme:  $theme<br><center>\n";

  $song =~ s/'//g;

   print "<A
a> &nbsp;-&nbsp\n";

   if(stat("$path/real/$realname")) {

   print "<A

  if($lyrics) {
   print "<a
   print "no lyrics";

  print "</td></tr></table>";

sub open_file {
  ($filevar, $filemode, $filename) = @_;

  if(open ($filevar,$filemode . $filename) ){
     open ($filevar,$filemode . $filename)
  }else {

sub open_file1 {
  ($filevar, $filemode, $groupTab) = @_;

  if(open ($filevar,$filemode . $groupTab) ){
     open ($filevar,$filemode . $groupTab)
  }else {

sub read_file {

  local ($filevar) = @_;


sub print_error {
 print "<h3>Sorry there are no links at this time for this

#for parsing form data
sub parse_form {

 local (*FORM_DATA) = @_;
 local ($method,$query,@key_value_pairs,$key_value,$key,$value);

   $method = $ENV{'REQUEST_METHOD'};

  if ($method eq "GET") {
     $query = $ENV{'QUERY_STRING'};
  }elsif($method eq "POST") {
      read(STDIN, $query, $ENV{'CONTENT_LENGTH'});
   print "ERROR unsupported method";

  #print $query , "\n";
   @key_value_pairs = split (/&/, $query);

     foreach $key_value (@key_value_pairs) {

     ($key, $value) = split(/=/, $key_value);
     $value =~ tr/+/ /;
    #print $key_value;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex ($1))/eg;

     $FORM_DATA{$key} = $value;

     #print "$key = $value<br>";
     #print "$FORM_DATA{formname}";

     $item = $FORM_DATA{'item'};

    #changing the file so that the value is more consistant.
    $nameGroup = $FORM_DATA{'file'};
    $nameHead = $FORM_DATA{'name'};
    $Artist = $FORM_DATA{'artists'};
    #convert tags with HTML
    $nameGroup =~ s/</\&lt;/g;

     if ($value eq "$FORM_DATA{'delete'}")  {
      $delete =  $FORM_DATA{'delete'};
       #print "DELETE <br>";
       $nameGroup = $FORM_DATA{'file'};
     $nameHead = $FORM_DATA{'name'};
     $Artist = $FORM_DATA{'artists'};
     #convert tags with HTML
     $nameGroup =~ s/</\&lt;/g;




sub delete_from {

#print "Content-type: text/html\n\n";

#$filename = "albums.txt";      # The database text file
$path ="/home/dots/public_html/gagorder/webdocs/gagorder"; #used to unlink
media files


while (@line = &read_file(FILE1)){

 $item =$item - 1;

 #print "item =" .$item;
 @database_row = @line;
    $x = $database_row[$item];

    @new_tab =  split(/\|/ , $x );

    #get name of group for use after we close this file
 $groupTab = "$new_tab[1].txt";

 #here now we must delete the album cover
 @getAlbumCover =  split(/\s*\|\s*/,$database_row[$item]);


 #now delete the song list record by using the delete function


   #print out the new values

   for($i = 0; $i <= scalar(@database_row); $i++) {
    if ($i == 0) {
     open (FILE1, ">$filename") ||  die "Cannot open File";
   print FILE1 "$database_row[$i]";
  print FILE1 "$database_row[$i]";

  close (FILE1);

} # End of while (<FILE1>)
close (FILE1);

    if (-e $groupTab) {
   #print "grouptab = $groupTab";

}#close sub

sub delete_song_list {
 $path ="yourpath"; #used to unlink media files
 #if a song list exist for this album, we must delete all the media files
associated with these items.
 #the real and mp3 files are indexes 5 and 6 in the songs list file must
read in file then delete files then unlink
 #$realname = $tab[5];
 #$mpname = $tab[6];

 while ($songline = &read_file(MUSICFILE)){
  @songtab =  split(/\s*\|\s*/,$songline);


   close (MUSICFILE);


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About