O'Reilly logo

Writing Apache Modules with Perl and C by Lincoln Stein, Doug MacEachern

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

F.2. Handling Forms

Another feature of Embperl is the way it helps you to handle forms. Posted form data is available in %fdat and @ffld. The hash %fdat contains the values of all form fields. The array @ffld contains the names in the order in which they were submitted.

Moreover, the HTML tags Input, Textarea, and Select take values from %fdat. If you do not specify a default value for an input tag, but a value for that input tag is available in %fdat, Embperl will automatically insert the value from %fdat and send it to the browser. This is similar to the behavior of CGI.pm. This means that if you post a form to itself, the browser will display the values you just entered.

Sometimes it's necessary to pass values between consecutive forms. One way to do this is to pass them via hidden form fields. The hidden metacommand creates hidden form fields for all fields not in another input field. This can be used to transport data through confirmation forms, for example, a wizard.

Example 6.1 shows many of the possibilities of Embperl. It's a simple form where you can enter your name, your email address, and a message. If you hit the send button, you see the data you just entered and can confirm the information by hitting the "send via mail" button, or you can go back to the input form to change the data. If you confirm your input, the data will be sent to a predefined email address. The example also shows how you can implement error checking—if you omit your name or your email address, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required