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, ...
Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.