$form

by Armaghan Saqib, Thursday, December 15, 2022, 00:45 (499 days ago) @ Armaghan Saqib
edited by Armaghan Saqib, Friday, December 23, 2022, 11:45

$form is a hash reference which contains the data sent by user through GET or POST http requests (whenever Save, Delete, Post buttons on forms are pressed). So, for example, if you had the following field in your form:

<input type=text name=firstname size=10 value="Armaghan Saqib">

You can access it with $form->{firstname} in your Perl code once that form is submitted.

It is also used as a global variable to store data temporarily read from database as needed. This makes it convenient to pass data around different 'subs' or modules.

$form is created in SL/Form.pm's 'sub new' and also converted into an object with 'bless' statement in the 'sub new'. This means that the functions and procedures in the SL/Form.pm can be used as properties and methods on the $form hash.

For example, you can format a number into the user specified number format with following code:

my $formatted_number = $form->($myconfig, 19290, 2);

And $formatted_number will contain "19,290.00".

Exercise:

Please open SL/Form.pm and go through all the subs to see what it has to offer.


Complete thread:

 RSS Feed of thread