Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can post back be implemented?

    Can we do any post back in perl and cgi?
    Pls advice.
    Thanks

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,947
    Thanks
    2
    Thanked 170 Times in 165 Posts
    Please rephrase your question. As it is, it doesn't make much sense.

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i'm doing html with perl and cgi.

    i have a test.cgi and test.pl

    what i do is in test.cgi, i have a form that post data to the test.pl which get the param from test.cgi. but after that, i wanted it to automatically post back or return back to the test.cgi script.

    can anyone guide me and advice me?
    thanks

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,947
    Thanks
    2
    Thanked 170 Times in 165 Posts
    How are you calling test.pl from test.cgi?

    Please post your scripts and explain what you want to transfer between them.

  • #5
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm using html in my script.
    In my test.cgi.

    i have a
    Code:
    Code:
    <form action="test.pl" method="post">
    which post
    Code:
    Code:
    <input type="text" name="a"> <input type="submit">
    In test.pl,

    i will get the parameter from test.cgi
    next, i wan to redirect or return back to test.cgi because it is my presentation page while test.pl is my logic page.

  • #6
    New Coder
    Join Date
    Oct 2006
    Posts
    68
    Thanks
    0
    Thanked 28 Times in 28 Posts
    Don't separate your logic and presentation. Keep them in the same script and just add conditions to determine if you're in POST mode.

    - Miller

  • #7
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,947
    Thanks
    2
    Thanked 170 Times in 165 Posts
    Personally, I think keeping the logic and presentation separate is a better approach, but for the presentation side I's use HTML::Template instead of the Perl script.

    http://search.cpan.org/~samtregar/HT....9/Template.pm

  • #8
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    @fishmonger - I dont really know how html-template work.
    Can u guide me?


    this is my code. after i post to test.pl, what is the method to forward back to presentation script, test.cgi?



    test.cgi

    Code:
    print "Content-type: text/html\n\n";
    print "<html><head>";
    print "<title>Test</title>";
    print "</head><body>";
    
    print "<form name=\"input\" action=\"test.pl\" method=\"post\">";
    
    print qq|Test Name: <input type="Text" name="testName">|;
    print qq|<input type="submit" value="Add"><br><hr>\n|;

    test.pl


    Code:
    use CGI qw(:standard);
    
    my $list = param("testerName");
    
    print "$list\n"

  • #9
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,947
    Thanks
    2
    Thanked 170 Times in 165 Posts
    test.tmpl: (presentation html template file)
    Code:
    <html>
    <head>
      <title>Test Template</title>
    </head>
    
    <body>
    
    <form name="input" action="test.pl" method="post">
    
    Test Name: <input type="Text" name="TestName">
    <input type="submit" value="Add">
    
    </form>
    <br><hr>
    
    <TMPL_IF NAME="TestName">
      <h2>Hello <TMPL_VAR NAME=TestName>,</h2>
      <p>How are you today?</p>
    </TMPL_IF>
    
    </body>
    </html>

    test.pl: (logic script)
    Code:
    #!/perl/bin/perl
    
    use strict;
    use warnings;
    use CGI;
    use HTML::Template;
    use CGI::Carp qw(fatalsToBrowser);
    
    # open the html template
    my $template = HTML::Template->new(filename => "$ENV{DOCUMENT_ROOT}/test.tmpl");
    my $cgi      = CGI->new;
    my %params   = $cgi->Vars;
        
    # fill in some parameter(s)
    $template->param(TestName => $params{'TestName'} );
    
    # send the obligatory Content-Type and print the template output
    print $cgi->header, $template->output;

  • #10
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks.
    Last edited by chez; 05-13-2011 at 04:17 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •