probe.pl
Die Standard-Testfunktion für Formulare
probe.pl verarbeitet die übergeben Daten unabhängig von den jeweiligen
Methoden der Übergabe zu einem Hash. Heute wird man allerdings eher das
cgi-Modul verwenden, das noch
viele andere Funktionen bietet.
Für das grundsätzliche Verständnis ist diese Funktion aber recht nützlich....
Quellcode probe.pl
Beispiel anschauen
(/cgi-local/probe.pl)
Quellcode
#!/usr/bin/perl
print "Content-type: text/html
"; # Ausgabe als HTML-Seite wird festgelegt
#------------------------------------------------------------------------
# Method GET or POST or ARGV
#-----------------------------------------------------------------------#
local ($i, $stringValues, $stringKeys, $subject, $toMail, $fromMail);
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}
else {
$in = $ARGV[0];
$in =~ s/\+/&/g;
}
#------------------------------------------------------------------------
# Umwandlung der Hex-Zeichen in Alphanumerischen Code
#-----------------------------------------------------------------------#
$in =~ s/%(..)/pack("c",hex($1))/ge;
$in =~ s/\+/ /g;
@in = split(/\&/,$in);
#---------------------------------
# Splitting KEY-VALUE-Pairs
#---------------------------------
foreach $i(0 .. $ #in) {
local($key, $val) = split(/=/,$in[$i],2);
$inputHash{$key}=$val;
}
print "<font face=arial size=2>
<h3>probe.pl</h3>
<B>Eingang von der cgi-Schnittstelle</B><XMP>$in</XMP></FONT>
<table border=1>
<tr bgcolor=yellow>
<th>Name</th>
<th>Wert</th>
</tr>";
foreach (keys(%inputHash)) {
print "<tr>
<td bgcolor=lightyellow><font face=arial size=2>$_</font></td>
<td><font face=arial size=2> $inputHash{$_}</font></td>
</tr>";
}
print "</TABLE>";
Formular zum Test
Ergebnis
Link
post:
get:
Quellcode
<a href="/cgi-local/probe.pl?wert0+wert1+wert2"> Link</a>
<hr>
post: <br>
<form action="/cgi-local/probe.pl" method="post">
<input type="text" name="inputField">
<input type="checkbox" name="checkboxField" value="ok">
<input type="radio" name="radioField" value="ok">
<input type="submit" name="submitfeld" value="abschicken">
</form>
get: <br>
<form action="/cgi-local/probe.pl" method="get">
<input type="text" name="inputField">
<input type="checkbox" name="checkboxField" value="ok">
<input type="radio" name="radioField" value="ok">
<input type="submit" name="submitfeld" value="abschicken">
</form>
Links
Ihr Browser kann derzeit kein
JavaScript, bzw. erkennt kein noscript. weshalb eine Reihe von Beispielen nicht funktionieren werden!
Verwenden Sie bitte einen moderneren JavaScript-fähigen Browser oder
aktivieren Sie JavaScript.
(München, 2001-04-08 14:12:18 /
)