Hi all,

QUESTION: How do you write the script so if someone enter serail number in fromcgi.pl and the otherfields, but after he submit, it will get part number from getpart.pl and write to default.db file Date|Serialnumber|Partnumber|Quantity|Extra
This will auto fill in partnumber (hidden field).

Code follows:

1. oneline form: formcgi.pl
#!/usr/bin/perl print "Content-type:text/html\n\n"; print <<EndOfHTML; <HTML> <HEAD> <TITLE>Test</TITLE> </HEAD> <BODY bgcolor=ffffff> <BR><center><h1><Font color=red>Check How it work</font></h1></center> <BR><center> <FORM name="submitform" action="http://testit.com/cgi-bin/addrecord.pl +" method="post" > <TABLE WIDTH=614 BORDER=1 CELLPADDING=4 CELLSPACING=3 STYLE="page-brea +k-before: always"> <COL WIDTH=187> <COL WIDTH=400> <TR VALIGN=TOP> <TD WIDTH=187> <P>Serial Number:</P> </TD> <TD WIDTH=400> <INPUT type="text" name="serialnumber" size="20"> </TD> </TR> <TR VALIGN=TOP> <TD WIDTH=187> <P>Part Number:</P> </TD> <TD WIDTH=400> <INPUT type="text" name="partnumber" size="20"> </TD> </TR> <TR VALIGN=TOP> <TD WIDTH=187> <P>Quantity:</P> </TD> <TD WIDTH=400> <INPUT type="text" name="quantity" size="20"> </TD> </TR> <TR VALIGN=TOP> <TD WIDTH=187> <P>Extra Opt:</P> </TD> <TD WIDTH=400> &nbsp;<SELECT NAME="DIMMOpt"> <OPTION SELECTED VALUE="null">Select Opt</OPTION> <OPTION>N/A</OPTION> <OPTION>Full POP</OPTION> <OPTION>Haft POP</OPTION> </SELECT> </TD> </TR> </TABLE> <P><INPUT type="submit" value="Run"><INPUT type="reset" value="Oops! S +tart again"></P> </FORM></center> EndOfHTML print "</BODY> </HTML>\n";
2. addrecord.pl
#!/usr/bin/perl print "Content-type:text/html\n\n"; use Time::Local; $today = timelocal(localtime); $now = &unix_to_date($today); sub unix_to_date { # -------------------------------------------------------- # Returns the date in the format "mm-dd-yyyy". # Warning: If you change the default format, you must also modify + the &date_to_unix # subroutine below which converts your date format into a unix ti +me in seconds for sorting purposes. my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $dayl +ight) = localtime(time()); ($day < 10) and ($day = "0$day"); $mon += 1; ($mon < 10) and ($mon = "0$mon"); $year += 1900; return "$mon\/$day\/$year"; } $datafile = "default.db"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $FORM{$name} = $value; } open(OUTF,">>default.db") or dienice("Couldn't open defaul +t.db for writing: $!"); # This locks the file so no other CGI can write to it at the # same time... flock(OUTF,2); # Reset the file pointer to the end of the file, in case # someone wrote to it while we waited for the lock... seek(OUTF,0,2); print OUTF "$now|$FORM{'serialnumber'}|$FORM{'partnumber'} +|$FORM{'quantity'}|$FORM{'DIMMOpt'}|\n"; close(OUTF); print <<EndHTML; <html><head><title>New record has been added !</title> <meta http-equiv="refresh" content="2; url=http://testit.com/cgi-bin/f +ormcgi.pl"> </head> <body> <center><h2>New record has been added today $now !</h2> <BR>Thanks !! </center> </body></html> EndHTML sub dienice { my($msg) = @_; print "<h2>Error</h2>\n"; print $msg; exit; } 3. getpart.pl This is a perl script from someone, it take serial number and give me +part number and it pulled from a website. <code> Example: $getpart 1234ABCD I will get the result is $501-1234-01
and here is the code:
#!/usr/bin/perl -w $numArgs = $#ARGV + 1; if ($numArgs == 1) { $INPUT = "$ARGV[0]"; } else { exit; } use LWP::Simple; $page = get("http://from/this/SfcStatus?sfcnumber=${INPUT}&tested=DONT +CARE"); #print $page ($plain_text = $page) =~ s/<[^>]*>//gs; @item=split(' ',$plain_text); #$count = 0; #foreach $i (@item) { # print "$count : $i\n"; # $count += 1; # } #exit; # First, find Shop Order, MFG Center, and Status foreach $i ( 30...60) { # print " $i $item[$i]\n"; if ( $item[$i] eq 'ORDER' ) { $SHOP = $item[ $i + 1 ]; if ( length $SHOP < 8 ) { $SHOP .= "\t"; } } elsif ( $item[$i] eq 'CENTER' ) { $MFG_CENTER = $item[ $i + 1 ]; if ( length $MFG_CENTER < 8 ) { $MFG_CENTER .= "\t"; } } elsif ( $item[$i] eq 'GROUP' ) { $ITEMGROUP = $item[ $i + 1 ]; } elsif ( $item[$i] eq 'STATUS' ) { $STATUS = $item[ $i + 1 ]; if ( length $STATUS < 8 ) { $STATUS .= "\t"; } last; } } # KEY: Part Number Serial Number Shop Order MFG CENTER STA +TUS if ( $item[60] eq 'DEKIT' ) { print "$item[34]\n"; } elsif ( $item[27] eq 'SHIP' && $item[60] ne 'DEKIT' ) { print "$item[34]\n"; } else { print "$item[26]\n"; }
Thanks

Edited by castaway - added readmore and moved question to top.


In reply to perl form by britney

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.