sub add_record {
&header("Add a Record");
This calls our header routine, and specifies the title of the page.
print qq~
<CENTER>
<FORM METHOD=POST>
<INPUT TYPE="hidden" NAME="action"
VALUE="add_record_two">~;
&build_record_page;
print qq~
<CENTER>
<INPUT TYPE="submit" value="Enter Into
Database"></CENTER>
<CENTER>
</FORM>~;
&footer;
}
This sub is the first step you take in adding your records. It presents you with a blank form, ready for you to enter information. Wait!!!! What is this &build_record_page
sub doing there? Let me explain this little diddy for ya.
sub build_record_page { my (%record) = @_;
This takes the input given to it, if any, and stores it in the hash %record
, as the only data sent to it would be in hash form.
my ($val) = "";
my ($html) = qq~<TABLE border=1 bgcolor="#FFFFFF"
cellspacing=0 cellpadding=4>
<TR bgcolor="#C0C0C0">
<TD colspan=2><CENTER><font size=-1> Record
</CENTER></TD>
</TR>~;
Standard HTML, but you probably don't need me to point that out
foreach $obj (@db_fields) {
Now we start to traverse through all of the fields we created at the start of the program.
if ($obj eq $db_key) {
next; # ID's are dynamically made, so why let
the user do it?
}
This makes sense, as users cannot create keys, as they may make copies. This just skips this step so uses won't be able to make the keys.
$html .= qq~<TR bgcolor="#DDDDDD"><TD><FONT
SIZE=-1>$db_name{$obj}</TD><TD>~;
if ($db_type{$obj} eq "text") { # Makes the text
box
# Make a input text field
if ($record{$obj}) { $val = qq~
VALUE="$record{$obj}"~; }
else { $val = ""; }
$html .= qq~<INPUT TYPE="text" NAME="$obj"
size="20" $val>~;
}
elsif ($db_type{$obj} eq "textarea") { # Makes the
textarea
# Make a textarea box instead
if ($record{$obj}) { $val = qq~$record{$obj}~; }
else { $val = ""; }
$html .= qq~<TEXTAREA NAME="$obj" ROWS="4"
COLS="40">$val</TEXTAREA>~;
}
$html .= qq~</TD></TR>~;
This block of code can look confusing. Remember those variables I declared in the @db_fields
area? Well, here they are put to use, such as $db_name
(readable version) and $db_type
, which determines the input type. Basically it prints out the name of the field and its info. Next, in the lines where $val
is being set, the script is looking if any data was sent to the sub routine. If so, it uses this data in the fields to be displayed. Otherwise, it just leaves the input fields blank.
}
$html .= "</TABLE><P>";
This just finishes off the $html
variable, and below, prints it.
print $html;
}
There you go, that sub is now explained.... hopefully :-)