The full tutorial with the whole listing of code is at:
Link to tutorial
I've included some of the original code snippets and what I have changed them to.
It originally listed these values as a hash of arrays.
I've tried changing it to:# Define Your Database Fields Here Like So # Field Name => [Number, 'Readable Name', 'type of field, two op +tions are text or textarea' #%fields = ( # ID => [0, 'Link ID:', + 'text'], # Name => [1, 'Name:', + 'text'], # Email => [2, 'E-Mail Address:', + 'text'], # Phone => [3, 'Phone Number:', + 'text'], # Address => [4, 'Street Address:', + 'textarea'] #);
The code that builds the form is as follows:%fields = ( ID => [0, 'Link ID:', + 'text'], change_type => [1, 'Type Of Change:', + 'drop'], change_summary => [2, 'Summary Of Change :', + 'text'], machines => [3, 'Machines involved :', + 'drop'], date => [4, 'Date of change:', + 'text'], time => [5, 'Time of change:', + 'text'], change_reason => [6, 'Reason for change:', + 'textarea'] ); %fields_drop = ( #types of system change 'sys' => 'sys', 'ops' => 'ops', 'cmd' => 'cmd');
Can anybody help please?sub build_record_page { my (%record) = @_; my ($val) = ""; my ($html) = qq~<TABLE border=1 bgcolor="#FFFFFF" cellspacing=0 cellpa +dding=4> <TR bgcolor="#C0C0C0"> <TD colspan=2><CENTER><font size=-1> Record </CENTER>< +/TD> </TR>~; foreach $obj (@db_fields) { if ($obj eq $db_key) { next; } $html .= qq~<TR bgcolor="#DDDDDD"><TD><FONT SIZE=-1>$d +b_name{$obj}</TD><TD>~; if ($db_type{$obj} eq "text") { # Makes the text box if ($record{$obj}) { $val = qq~ VALUE="$record +{$obj}"~; } else { $val = ""; } $html .= qq~<INPUT TYPE="text" NAME="$obj" siz +e="20" $val>~; } if ($db_type{$obj} eq "drop") { # Makes the dropdown +box if ($record{$obj}) { $val = qq~ VALUE="$record +{$obj}"~; } else { $val = ""; } $html .= qq~<SELECT NAME="$obj +" <option value=""></option> $val>~; # The bit that I am stuck on I n +eed to populate a drop down box from the fields_drop hash, but that n +eeds to depend on which whether it is the type of change, or the mach +ines to which the change will be applied. } elsif ($db_type{$obj} eq "textarea") { # Makes the tex +tarea if ($record{$obj}) { $val = qq~$record{$obj}~; + } else { $val = ""; } $html .= qq~<TEXTAREA NAME="$obj" ROWS="4" COL +S="40">$val</TEXTAREA>~; } $html .= qq~</TD></TR>~; } $html .= "</TABLE><P>"; print $html; }
In reply to Using drop down boxes in a CGI script by wishartz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |