#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    hello everybody
    I have a question that might sound really stupid to al of you but I am just beginning with perl and I would like to know how to receive data in a perl script from a html form, with other words: how do I tell the script what to do with the information it gets from that form.
    I guess this is as simple as anything but I hope someone will take a little time and give me that answer...
    THANK YOU!


    ------------------
    visit
    www.gsm-plaza.com
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>how do I tell the script what to do with the information it gets from that form

    Add a form parsing subroutine like below, then $FORM{'name'} or $FORM{'email'} will give you the value from <input type="text" name="name"> and <input type="text" name="email">

    #!/usr/local/bin/perl

    &parse_form;

    sub parse_form {
    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/<!--(.|n)*-->//g;
    $value =~ s/<([^>]|n)*>//g;
    $FORM{$name} = $value;
    }
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    HI!
    thanx to the information I got previously I made this simple guestbook but now I get the following error:

    sh: +": bad option
    sh: +": bad option

    I don't know what it means and I don't know what to change so if anyone could help me???
    thank you

    #!/usr/local/bin/perl


    $date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
    $shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);

    &parse_form;

    sub parse_form {

    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/<!--(.|n)*-->//g;
    $value =~ s/<([^>]|n)*>//g;
    $FORM{$name} = $value;
    }
    }

    open (GUEST,"guest.html") &#0124; &#0124; die "Can't open guest.html!n";
    @lines=<GUEST>;
    close(GUEST);
    $SIZE=@LINES;

    open (GUEST,"guest.html") &#0124; &#0124; die "Can't open guest.html!n";

    for ($i=0;$i<=$SIZE;$i++) {
    $_=$LINES[$i];

    if (/<!--begin-->/)
    {
    print GUEST "<!--begin-->";
    }
    print GUEST "<p>$FORM{'message'}<p>n";
    print GUEST "<a href="mailto:$FORM{'email'}">$FORM{'name'}</a>$date<p>n";
    print GUEST "<hr width=50%>n";
    print GUEST $_;
    }

    close (GUEST);




    ------------------
    visit
    www.gsm-plaza.com
  6. #4
  7. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    14
    Little less work if you want to use CGI:
    #!/usr/local/bin/perl
    use CGI;
    my $cgi = new CGI;
    $textbox = $cgi->param("entered");
    $textbox =~ s/n/<br>/g;
    $textbox =~ s/<|>//g;
    print $cgi->header;
    print "<br>";
    print $textbox;
  8. #5
  9. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    1) To write to guest.html, you need >>
    open (GUEST,">>guest.html") | | die "Can't open guest.html!n";
    for ($i=0;$i<=$SIZE;$i++) {

    2) Make sure your script sends a successful page or redirects to the viewguest page.

    3) $SIZE=@LINES;
    needs to be $SIZE=@lines;

    Try to download wwwboard and play with it.

  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    hey, I changed what you said but it still won't work...
    know anything else to change??
    would help me a lot
    thank you



    ------------------
    visit:
    - <A HREF="http://www.gsm-plaza.com
    -" TARGET=_blank>www.gsm-plaza.com
    -</A> givan.isfunky.com
  12. #7
  13. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>know anything else to change??

    Yes. Remove all the following lines or rewrite your script
    $SIZE=@LINES;

    open (GUEST,"guest.html") | | die "Can't open guest.html!n";

    for ($i=0;$i<=$SIZE;$i++) {
    $_=$LINES[$i];

    As I mentioned, you should try wwwboard. Please go to http://www.worldwidemart.com/scripts/
  14. #8
  15. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    I assume that the form you're sending the information from is using the POST method right? If it's using the GET method (or no method is specified) you'll need to use a different parsing routine.

    I'm not going to bother going through your code to find a problem, just do as freebsd said and use one that's already made.

    One more note: make sure guest.html is chmoded 777.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    Thanks to all of you but I don't think I'll learn anything from just using someoneelses guestbook, it isn't about the guestbook, but about making such a programm myself



    ------------------
    visit:
    - <A HREF="http://www.gsm-plaza.com
    -" TARGET=_blank>www.gsm-plaza.com
    -</A> givan.isfunky.com
  18. #10
  19. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>it isn't about the guestbook, but about making such a programm myself

    Yes, but not quite. The technique you are using..

    if (/<!--begin-->/){
    print GUEST "<!--begin-->";

    is exactly the same as wwwboard. So I told you to check out wwwboard earlier and see how it works. Of course, if you are confidence enough, you can always write your own guestbook. On the other hand, if you are struggling with specific part of your script, you should immediately download wwwboard to get/steal some ideas.

    >>I don't think I'll learn anything from just using someoneelses guestbook

    Right, don't use the exact guestbook. Wrong, since you need to alter it and learn from it.

IMN logo majestic logo threadwatch logo seochat tools logo