Perl Script that gets data from a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chanshaw
    New Member
    • Nov 2008
    • 67

    Perl Script that gets data from a form

    Alright I just want to get the entered data from the html form and process it to store it as a variable can someone give me an example of this please.

    Code:
    #!c:\perl\bin\perl -t
    use strict;
    use warnings;
    
    $user_input =
    I'd like the $user_input to be whatever the user entered in the guessedNumber text input.

    Html
    Code:
    <form METHOD="POST" ACTION="guessNumber.cgi">
    Guessing Game<br>
    <br><br>
    Enter a number between 1 & 100 <br>
    Guess:  <input type="text" name="guessedNumber" maxlength=3 size=5><br>
    <input type="submit" value="Enter Guess">
    <input type="reset" value="Reset"><br>
    <input type="hidden" name="msgDisplay" value="Display Message">
    </form>
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    If you search this forum you will find many examples of getting data from a form. Here is a link to a script I did as an example. It also uses HTML::Template.

    It is a nice example. Also, check the documentation for the CGI.pm as well.

    --Kevin

    Comment

    • chanshaw
      New Member
      • Nov 2008
      • 67

      #3
      Could you just make an example from the information I gave or am I lacking information to give an example or is my question to complicated to give a quick example? It's just I find your example long and complicated and a little hard to understand for what I need to do.

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        In the future, please do try and search Google for the answers that you seek before posting here. You will learn more if you get the answer on your own and figure it out than if you wait for an answer here.

        A quick google search like this would have provided plenty of links for you to figure this out.

        Regards,

        Jeff

        Comment

        • eWish
          Recognized Expert Contributor
          • Jul 2007
          • 973

          #5
          Your example is not to complicated. Here is a more basic example.

          Code:
          #!/usr/bin/perl -T
          
          use strict;
          use warnings;
          
          use CGI;
          use CGI::Carp qw/fatalsToBrowser/;
          
          my $q = CGI->new;
          my $user_input = $q->param('guessedNumber');
          
          print $q->header;
          print $user_input;
          
          1;
          Is that more of what you are looking for?

          --Kevin

          Comment

          • chanshaw
            New Member
            • Nov 2008
            • 67

            #6
            Yea thanks for simplifying that.

            Comment

            Working...