Hello Monks,
I have a simple html form.(Month Day Year Title and Message) input fields are used.
<form method="POST" action="http://www.dom.com/cgi-local/events.cgi">
<input type="hidden" name="action" value="preview">
<input type="submit" value="Preview" name="B1">
<input type="reset" value="Reset" name="B2">
</form>
When the form is submited the cgi script displays the variable information and formatting correctly.
#!/usr/local/bin/perl -w
use strict;
use diagnostics;
use CGI qw(:standard);
my $q = new CGI;
my $action = $q->param('action');
#############################
#initialize form variables
#############################
#my $uniq_number = &uniqueid;
my $month = param('month');
my $date = param('date');
my $year = param('year');
my $title = param('title');
my $message = param('message');
my $placement = param('placement');
#PLACES NEW EVENT BEFORE OR AFTER EXISTING EVENTS
################################
# variables for storage
###############################
my $data = join '::', $month,$date,$year,$title,$message;
my $addfile = "events.txt";
my $line = "";
######################################
#BEGIN COUNTCURRENTRECORDS SUBROUTINE
######################################
open(FILE, "$addfile");
my @lines = <FILE>;
close(FILE);
my $num = @lines;
######################################
if($action =~ /add_event/i){
&store_event;
}
##############################
# Print New Event for approval
##############################
# Add the event passed variables from the add event page
print header(),
start_html(-title=>'CGI Example Script'),
h2('New Parish Event!'),
"<HR>
<table border='0' width='100%'>
<tr>
<td width='100%'>
<table border='1' width='100%'>
<tr>
<td width='100%'>
<table border='1' width='100%'>
<tr>
<td width='22%'>
<font SIZE='+1'color='gray'><B>$month $date, $year</B>
</font></td>
<td width='78%'>
<font SIZE='+1'color='black'>
<B>$title</B></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width='800%'><font SIZE='2'>$message</font>
</td>
</tr>
</table>
</td>
</tr>
</table> <BR>
<form action method='post'>
<input type='hidden' name='action' value='add_event'>
<input type='submit' value=' Publish new event '>
<BR>
<INPUT type='button' value='Continue'onClick='history.go(-1)'>
</form>",
end_html();
#####################################
#could be sub for saving data
####################################
#####################################
# Open the file for appending
###################################
sub store_event{
if ($placement eq "beg") {
open (FH, "<events.txt") || die "could not open file: $!";
my @ODB = <FH>; close (FH);
my $newline = "$data";
open (NFH, ">events.txt") || die "could not open file 2: $!";
print NFH "$newline" . "\n";
foreach $line (@ODB) { print NFH "$line";
}
close (NFH);
}
else
{
open (OUT, ">>$addfile") or die "Can't open $addfile\n";
print OUT "$data\n";
close OUT;
}
}
exit (0);
At this point I wanted to be able to write the variables to a file or go back and continue editing. But I am still new to perl and I am having a lot of trouble.
Thanks for any help
Cal
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.