1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
Example Code for using Embperl::Forms and the wizard.pl application
===================================================================
On Unix you can access this example using
make start
and then accessing
http://localhost:8531/eg/forms/wizard/action.epl
Continue with step 6
On Windows this example assumes that Embperl is extracted under
C:\perl\msrc\embperl
and Apache is installed at
C:\Programme\Apache Software Foundation\Apache2.2
In this example Embperl is installed on Windows and uses Apache as CGI script.
The same should also work with mod_perl and Unix. You only have to modify
the httpd.conf accordingly.
The example assumes the Perl is already install and available in your PATH.
1.) First of all install Embperl
cd C:\perl\msrc\embperl
perl Makefile.PL
-> Answer all question with 'N' (because we don't use mod_perl in this example)
nmake
nmake install
2.) Copy CGI Script to Apache directory
copy epocgi.pl "C:\Programme\Apache Software Foundation\Apache2.2\cgi-bin"
copy embpcgi.pl "C:\Programme\Apache Software Foundation\Apache2.2\cgi-bin"
3.) Modify the configuration file
It is located at
C:\Programme\Apache Software Foundation\Apache2.2\conf\httpd.conf
At the end add the following directives:
# ----------------------------
AddType text/html .epl
AddType text/html .ehtml
Alias /forms c:/perl/msrc/embperl/eg/forms
SetEnv PERL5LIB c:/perl/msrc/embperl/eg/forms
SetEnv EMBPERL_OBJECT_ADDPATH c:/perl/msrc/embperl/eg/forms/lib
SetEnv EMBPERL_SESSION_HANDLER_CLASS no
# optAllFormData + optRawInput
SetEnv EMBPERL_OPTIONS 0x2010
<Location /forms/pages>
Order allow,deny
Allow from all
Action text/html /cgi-bin/embpcgi.pl
Options ExecCGI
</Location>
<Location /forms/wizard>
Order allow,deny
Allow from all
Action text/html /cgi-bin/epocgi.pl
Options ExecCGI
SetEnv Embperl_Appname setupwizard
SetEnv Embperl_Object_Base base.epl
SetEnv Embperl_Object_App wizard.pl
</Location>
# ----------------------------
4.) Start Apache on the command line
cd C:\Programme\Apache Software Foundation\Apache2.2
bin\httpd
-> Apache will write it's logfiles in C:\Programme\Apache Software Foundation\Apache2.2\logs
5.) Call a simple page
Per default Apache listens on Port 8080 on Windows, in case you have installed
it on a different port please change the followings URLs accordingly.
Open the following URL in a browser:
http://localhost:8080/forms/pages/loop.htm
This shows the environemnt of the CGI script. This is a very simple Embperl page.
6.) Calls the wizard
Open
http://localhost:8080/forms/wizard/action.epl
This will show you a wizard where you can enter setup information. The wizard will
ask page by page what is necssary. It will ask different things depending on your input.
For example you can choose different ways to get to the internet and it will ask the
access data (can call different pages internaly) depending on your choise.
If you choose "import" on the first page, you get an form that modifies itself dynamicly
depending on what type you chosse at the top of the page.
7.) The files
Here is an overview of all files underneath the eg/forms directory:
- eg\forms/Embperl:
Directory for modules of the Embperl::MyForm namespace which are used to customize
the forms and add addtional controls
* MyForm.pm
This defines the Embperl::MyForm Object which overwrites some methods to tell
Embperl::Form where to located additional objects.
- eg\forms/Embperl/MyForm/Control:
Directory for Custom controls
- eg\forms/Embperl/MyForm/DataSource:
Directory for custom datasource objects. Datasource object are used to fill
select or radio controls, as far as they don't have static data in the form
definition itself. Use the datasrc => attribute to specify a datasource object.
The example comes with two datasource
objects. These two only return static data, but datasource objects can return
any data for example from a database.
* languages.pm
* netmask.pm
- eg\forms/css:
* EmbperlForm.css
Stylesheets
- eg\forms/js:
* EmbperlForm.js
* prototype.js
Necessary JavaScript code
- eg\forms/lib:
Generaly code
* footer.epl
This file is included in every page at the bottom. It is called from base.epl
* header.epl
This file is included in every page at the top. It is called from base.epl
* wizard.epl
This file contains the HTML layout for the wizard. It contains several methods
which can be overwritten in the page objects to customize the layout.
* wizard.pl
Thie is the controller object of the wizard. It controls the workflow.
- eg\forms/pages:
* loop.htm
Simpley Embperl page as example
- eg\forms/wizard:
This directory contains the actual pages of the wizard and it's configuration
* base.epl
This file defines the HTML layout of the page in which ths wizard is embedded.
* wizconfig.pl
This file contains the configuration of the wizard.
The method "getpages" must return an array ref of all page files that are
used by the wizard.
The method "init" is called on every request and can be used for initialization
purposes.
Every of the remaining files in the directory define a page for the wizard:
action.epl
do.epl
dsl.epl
exportslave.epl
finish.epl
gateway.epl
importslave.epl
inetconnect.epl
isdn.epl
name.epl
network.epl
organisation.epl
Every page contains four methods:
- title:
Is used to specify the title of the page
- condition:
The page is only displayed if the method return true, otherwise it is skipped
- show:
This method contains the code and HTML which is actually shown for the page,
including the form elements.
- verify:
This method is called after the user has pressed Next. If it is used to verify
the user input. If the input is ok, it should return true, othwise it should
return 0 and set $fdat{-msg} to the error message.
8.) Inclunding forms
A form is defined by a fields definition which is passed to the showfields method.
A fields definition consists of a set of controls. Each control has a set of
attributes.
Available controls can be found at embperl/Embperl/Form/Control
Each control contains a description of the possible attributes.
Some controls (like select, selectdyn, radio, checkboxes) can get it's input
from a datasource control (see above). In the example code most of the datasrc
attributes are renamed to xdatasrc because the datasource object are not
included in the example code.
Each control definition can also contain a validation rule. See Embperl::Form::Validate
for more informaion on validation rules.
|