Vraag & Antwoord

Webprogrammeren & scripting

Weergave door elkaar

3 antwoorden
  • Hallo, Ik heb een html formulier gemaakt op basis van het dit [url]http://users.skynet.be/javascript/forms/HTMLform.htm[/url]voorbeeld. Ik gebruik een cgi script. Het probleem is dat bij binnenkomst alle regels door elkaar staan (zie voorbeeld). Graag wil ik alle regels in de volgorde van het web formulier. wie wil mij verder helpen? Voorbeeld binnengekomen formulier: [code:1:4a17242308]a_keuze: on b_keuze: on c_keuze: on commentaar: Jouw commentaar: gemeente: gemeente naam: Naam nr: 1 postnr: 1234 rondje: 1 straat: Straat [/code:1:4a17242308] voorbeeld cgi script: [code:1:4a17242308]#!/usr/bin/perl # # mailer.pl-- A simple program to mail form data to an email address # # Written in 1997 by James Marshall, james@jmarshall.com # For the latest, see <a href="http://" target="_blank">http://</a> IMPORTANT: MAKE SURE THESE TWO VALUES ARE SET CORRECTLY FOR YOU! $mailprog= "/usr/sbin/sendmail" ; $recipient= "info\mijndomein.com" ; # make sure to \ escape the @ # Get the CGI input variables %in= &getcgivars ; # Open the mailing process open(MAIL, "|$mailprog $recipient") || &HTMLdie("Couldn't send the mail (couldn't run $mailprog).") ; # Print the header information $ENV{'HTTP_REFERER'} || ($ENV{'HTTP_REFERER'}= "your Web site") ; print MAIL "Subject: van mijndomein.nl\n\n", "verzonden via $ENV{'mijndomein.nl'}:\n\n" ; # Find length of longest field name, for formatting; include space for colon $maxlength= 0 ; foreach (keys %in) { $maxlength= length if length > $maxlength ; } $maxlength++ ; # Print each CGI variable received by the script, one per line. # This just prints the fields in alphabetical order. To define your own # order, use something like # foreach ('firstname', 'lastname', 'phone', 'address1', ... ) { foreach (sort keys %in) { # If a field has newlines, it's probably a block of text; indent it. if ($in{$_}=~ /\n/) { $in{$_}= "\n" . $in{$_} ; $in{$_}=~ s/\n/\n /g ; $in{$_}.= "\n" ; } # comma-separate multiple selections $in{$_}=~ s/\0/, /g ; # Print fields, aligning columns neatly printf MAIL "%-${maxlength}s %s\n", "$_:", $in{$_} ; } # Close the process and mail the data close(MAIL) ; # Print an HTML response to the user print <<EOF ; Content-type: text/html <html> <style type="text/css"> <!-- .style3 {font-size: 18px} .style5 {font-family: Tahoma; color: #000000;} --> </style> </head> <body> <h3> </h3> <table width="100%" border="0"> <tr> <td><div align="center" class="style3"> <p class="style5">Uw bericht is verzonden</p> <p class="style5"><br /> Wij zullen zo spoedig mogenlijk uw bericht beantwoorden.</p> </div></td> </tr> </table> <h3> </h3> </body> </html> EOF exit ; #-------------- start of &getcgivars() module, copied in ------------- # Read all CGI vars into an associative array. # If multiple input fields have the same name, they are concatenated into # one array element and delimited with the \0 character (which fails if # the input has any \0 characters, very unlikely but conceivably possible). # Currently only supports Content-Type of application/x-www-form-urlencoded. sub getcgivars { local($in, %in) ; local($name, $value) ; # First, read entire string of CGI vars into $in if ( ($ENV{'REQUEST_METHOD'} eq 'GET') || ($ENV{'REQUEST_METHOD'} eq 'HEAD') ) { $in= $ENV{'QUERY_STRING'} ; } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { if ($ENV{'CONTENT_TYPE'}=~ m#^application/x-www-form-urlencoded$#i) { length($ENV{'CONTENT_LENGTH'}) || &HTMLdie("No Content-Length sent with the POST request.") ; read(STDIN, $in, $ENV{'CONTENT_LENGTH'}) ; } else { &HTMLdie("Unsupported Content-Type: $ENV{'CONTENT_TYPE'}") ; } } else { &HTMLdie("Script was called with unsupported REQUEST_METHOD.") ; } # Resolve and unencode name/value pairs into %in foreach (split(/[&;]/, $in)) { s/\+/ /g ; ($name, $value)= split('=', $_, 2) ; $name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ; $value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ; $in{$name}.= "\0" if defined($in{$name}) ; # concatenate multiple vars $in{$name}.= $value ; } return %in ; } # Die, outputting HTML error page # If no $title, use a default title sub HTMLdie { local($msg,$title)= @_ ; $title= "CGI Error" if $title eq '' ; print <<EOF ; Content-type: text/html <html> <head> <title>$title</title> </head> <body> <h1>$title</h1> <h3>$msg</h3> </body> </html> EOF exit ; } #-------------- end of &getcgivars() module -------------------------- [/code:1:4a17242308]
  • Het antwoord staat gegeven in de commentaarregels: [code:1:7e1b8fad54] # Print each CGI variable received by the script, one per line. # This just prints the fields in alphabetical order. To define your own # order, use something like # foreach ('firstname', 'lastname', 'phone', 'address1', ... ) { [/code:1:7e1b8fad54] Met andere woorden, regel 33 uit je code zou dan moeten worden: [code:1:7e1b8fad54] foreach ('naam', 'straat', 'nr', 'postnr', 'gemeente', 'rondje', 'a_keuze', 'b_keuze', 'c_keuze', 'commentaar') { [/code:1:7e1b8fad54] (ongetest)
  • [quote:d5afb862b3="Annie"]Het antwoord staat gegeven in de commentaarregels: [code:1:d5afb862b3] # Print each CGI variable received by the script, one per line. # This just prints the fields in alphabetical order. To define your own # order, use something like # foreach ('firstname', 'lastname', 'phone', 'address1', ... ) { [/code:1:d5afb862b3] Met andere woorden, regel 33 uit je code zou dan moeten worden: [code:1:d5afb862b3] foreach ('naam', 'straat', 'nr', 'postnr', 'gemeente', 'rondje', 'a_keuze', 'b_keuze', 'c_keuze', 'commentaar') { [/code:1:d5afb862b3] Annie Hartelijk bedankt voor je hulp. Heb jij overigens nog iets vreemds zien staan in het script (bijvoorbeeld op beveiliging gebied?) En succes met de tweede (ongetest)[/quote:d5afb862b3]

Beantwoord deze vraag

Weet jij het antwoord op deze vraag? Registreer of meld je aan met je account

Dit is een gearchiveerde pagina. Antwoorden is niet meer mogelijk.