FreeRollen has asked for the wisdom of the Perl Monks concerning the following question:

I am currently trying to learn pearl and cgi. I have existing website that I developed in html. I would like to make a simple form that takes an input and outputs a results to the same form in the same html page. I found lots of examples online. However, every CGI example i found on the web has my zip.plx script creating a new web page with my results. Is there a way to accomplish this with just one page.. ;;;;; <HTML><HEAD><TITLE>Learning Perl & CGI </TITLE></HEAD> ........ Other Stuff is here already <FORM METHOD=GET ACTION="/cgi-bin/zip.plx">

Enter your Zip Code: <INPUT NAME="zipcode" TYPE=TEXT>

<INPUT NAME="OK"TYPE=SUBMIT>

<Result of zip.plx go here

</FORM> ........... Other stuff is here already </HTML>

Replies are listed 'Best First'.
Re: PERL and CGI
by Argel (Prior) on Jun 04, 2010 at 00:37 UTC
    The web by it's very nature is stateless. Someone can hit a web page and leave it loaded in their browser for days before doing something with it again. That's why if you are using just straight HTML and CGI you will have to create a new web page.

    Naturally, people have devised ways to work around this. One example is using cookies to track state. Another is JavaScript, which brings us to pemungkah's node above, where he mentions AJAX. Ajax is what you are looking for, but that means even more stuff for you to learn. Personally, I would suggest you play with Perl CGI a bit more to get a better handle on how the technology works before moving on to more advanced topics.

    Elda Taluta; Sarks Sark; Ark Arks

Re: PERL and CGI
by pemungkah (Priest) on Jun 03, 2010 at 22:44 UTC
    I'm not 100% sure of your question, partly due to the somewhat confusing formatting.

    When you say "outputs a result to the same form in the same HTML page", do you mean an AJAX-like setup, where the page doesn't reload, or do you mean a more traditional CGI setup where the user hits submit and then the page reloads with updates? The two answers are quite different.

Re: PERL and CGI
by desemondo (Hermit) on Jun 04, 2010 at 02:31 UTC
    If I'm understanding you correctly you might be able to create an iframe that displays your script's form and cause it to appear as being in the same page.

    eg.
    <html> <body> <iframe title="Form" frameBorder="0" width="100%" height="100%" src="f +orm.pl" > </iframe> </body> </html>
Re: PERL and CGI
by Anonymous Monk on Jun 03, 2010 at 21:58 UTC
    It is Perl. Not PERL or pearl.

    See Writeup Formatting Tips for information on using code tags.

    Welcome to the Monastery!