Amit - Sorry about the delay in getting a response to you but I've been running pretty far behind with all the holiday's here in the states. I'm not really a perl hacker (more of a perl diddler) so I'm forwarding your request for help to the mac-perl list in hopes that they can help you out. The subroutines you ask about save_parameters, restore_parameters, and clean name do pretty much what they say: save a query to disk, restore the query from disk, and clean a filename of illegal (or unwanted) characters. But I think your real question how the CGI module works [I haven't used this particular module yet]. The pod that ships with the CGI.pm module explains most of it. Open Shuck, do a file open browse to your MacPerl folder, open the lib folder, select cgi.pm and read the description section of the CGI.pm POD (plain old documentation). It describes alot of what is going on. Kevin >Dear Kavin: > >I am trying to understand the complexities of putting up a form >and generate response. I have copied it from a tutorial. I tried >put in my staff. I designed a Submission form using PageMill. >I am sending the form as an attachment. I will be very happy >if you add some suggestions to it. Anything that you say will >help me to move a step forward. > >Best regards >Amit > > >#!/usr/local/bin/perl > >use CGI; >$query = new CGI; > >print $query->header; >print $query->start_html("SampleForm.html"); >print "<H1>Sample Form</H1>\n"; > ># Here's where we take action on the previous request >&save_parameters($query) if $query->param('action') eq >'save'; >$query = &restore_parameters($query) if $query->param('action') eq >'restore'; > ># Here's where we create the form >print $query->startform; ># Does this define the name value? >print $query->textfield(-name=>'field_name', > -default=>'starting value', -size=>50, >-maxlength=>80); >#Does this define Male & Female values >print$query->radio_group(-name=>'group_name',-values=>['Male','Female'], > >#Define Address > print $query->textfield(-name=>'field_name', -default=>'starting >value', > -size=>50, -maxlength=>80); >#Define Email > print $query->textfield(-name=>'field_name', > -default=>'starting value', -size=>50, >-maxlength=>80); >Define Occupation >print$query->radio_group(-name=>'group_name',-values=>['Business', >'Employment', 'Professonal'] >Define income >print $query->textfield(-name=>'field_name', 'secret'; > -default=>'starting value', -size=>50, >-maxlength=>80); >#Define Do you wish to join the mailing list >print$query->radio_group(-name=>'group_name',-values=>['Yes','No'], ><hr> >#Define a submit button > print $query->submit(-name=>'button_name', -value=>'value'); >#Define a reset button >print $query->reset >#Define End of Form >print $query->endform; > >print "Save/restore state from file: >",$query->textfield('savefile','state.sav'),"\n"; >print$query->radio_group(-name=>'group_name',-values=>['Male','Female'], >"\n"; >print $query->textfield(-name=>'field_name', -default=>'starting >value',"\n"; >print $query->textfield(-name=>'field_name',"\n"; >print$query->radio_group(-name=>'group_name',-values=>['Business', >'Employment', 'Professonal'],"\n" >print $query->textfield(-name=>'field_name', 'secret';"\n"; >print$query->radio_group(-name=>'group_name',-values=>['Yes','No'],"\n"; > >print "<P>"; > >print "<P>"; >print >$query->submit('action','save'),$query->submit('action','restore'); >print $query->submit('action','usual query'); >print $query->endform; > ># Here we print out a bit at the end >print $query->end_html; >------------------------------------------------------------------------------- >------------- > >Kevin: > >I am unable to understand after this part. Can you explain. > >sub save_parameters { > local($query) = @_; > local($filename) = &clean_name($query->param('savefile')); > if (open(FILE,">$filename")) { > $query->save(FILE); > close FILE; > print "<STRONG>State has been saved to file >$filename</STRONG>\n"; > } else { > print "<STRONG>Error:</STRONG> couldn't write to file $filename: >$!\n"; > } >} > >sub restore_parameters { > local($query) = @_; > local($filename) = &clean_name($query->param('savefile')); > if (open(FILE,$filename)) { > $query = new CGI(FILE); # Throw out the old query, replace it >with a new one > close FILE; > print "<STRONG>State has been restored from file >$filename</STRONG>\n"; > } else { > print "<STRONG>Error:</STRONG> couldn't restore file $filename: >$!\n"; > } > return $query; >} > ># Very important subroutine -- get rid of all the naughty ># metacharacters from the file name. If there are, we ># complain bitterly and die. >sub clean_name { > local($name) = @_; > unless ($name=~/^[\w\._-]+$/) { > print "<STRONG>$name has naughty characters. Only "; > print "alphanumerics are allowed. You can't use absolute >names.</STRONG>"; > die "Attempt to use naughty characters"; > } > return $name; >} > >Content-Type: text/html; charset=us-ascii; x-mac-type="54455854"; >x-mac-creator="53744D6C"; name="SampleForm.html" >Content-Transfer-Encoding: 7bit >Content-Description: Adobe PageMill* 1.0.2 Document >Content-Disposition: inline; filename="SampleForm.html" >Content-Base: "file:///Hard%20Disk/Desktop%20Folder/S > ampleForm.html" > > > > > Burlington's Introduces On-Line Shopping!! > > > > Before you enter the On-line Shopping spree > We would like to have a little information about you. > > > Name: Sex:MaleFemale > Mailing address: > E Mail: > > Occupation:BusinessEmploymentProfessional > Annual Income: > Do you wish to join the mailing list:Yes No > > >Please check the Submit button on completion of the form > If you with to change your information, press Reset Button > > > > > > ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch