HTML Pages can be created manually from OptiPerl's editor, or a HTML authoring tool can be used. Most HTML editors support creating forms and adding elements in it like textboxes and buttons.

 

1) Microsoft's Frontpage

 

In Microsoft Frontpage, select menu Insert / Form / Form element to add a form. This will also add automatically "submit" and "cancel" buttons. Then from the same menu add other elements you want. For an example we will add a "One liner text box". Right click on the text box and select "Form field properties". As a name enter "textfield". Right click again and select "Form Properties", check "send to other", select "CGI script" and press the Options button. Select as method "POST" and as action enter the perl script that will be called when the submit button is pressed, like

 

/cgi-bin/form.pl

 

See the next section on where to save the html file and how to create form.pl.

 

2) Manually in OptiPerl

 

Select New / HTML and enter:

 

<form method="POST" action="/cgi-bin/form.pl">

<p><input type="text" name="textfield" size="20"></p>

<p><input type="submit" value="Submit" name="submit"><input type="reset" value="Reset" name="reset"></p>

</form>

 

again in the first line the method and action is entered.

 

 

Where to save the html document

 

Included in OptiPerl's installation folder is the folder webroot used for all it's examples. Save the html to the folder

c:\program files\optiperl\webroot with the name test.htm

 

 

Creating form.pl

 

Now we will create the script that processes the input (what the user entered in the text box) and prints a page depending on it. Select menu New / Script and enter:

 

#!perl

 

use CGI qw(:standard);

print header;

$text = param('textfield');

print "<html><body>$text</body</html>";

 

Save this as form.pl in the folder c:\program files\optiperl\webroot\cgi-bin

This is a simple script that only prints back the text field.

 

Running

 

Go to menu Server and select both "Run with server" and "internal server enabled". Afterwards, make sure the last line of the menu shows "(internal) c:\program files\optiperl\webroot".

 

Open the html page (test.htm) in optiperl and press run. Test the submit button.

 

What is going on

 

Three things are important here:

 

1) Notice the form of the html page:

 

<form method="POST" action="/cgi-bin/form.pl">

 

This tells the browser to use a POST method (read more about methods) to send the text of the edit box. The action tells the browser what to do when the submit button of the form is pressed; here it will call /cgi-bin/form.pl

 

2) Also notice the path to the script used. We are calling form.pl in the folder /cgi-bin. This is why we saved form.pl in the cgi-bin folder of c:\program files\optiperl\webroot and also set the internal server webroot to c:\program files\optiperl\webroot.

 

3) To see what exactly happens when you press the "Submit" button, see the "Server talk" tab of the web browser.

 

Sending the query manually with the query editor

 

You can also run form.pl directly and have optiperl send the information it needs. Open the query editor, and from the "methods" menu enable the POST method and disable the other. Enter a name and value pair in the POST tab:

 

Name: textfield

Value: text entered in text box

 

Top  Previous  Next