?
Solved

Help needed with hidden fields and current date

Posted on 2003-02-18
14
Medium Priority
?
168 Views
Last Modified: 2013-12-25
I am trying to use a hidden field in a form, but I am trying to get it to automaticly generate the date. I am using the following line:

<FORM METHOD="POST" ACTION="/cgi-bin/tester.pl">
<b><font face="Verdana" size="2">KBID</font></b>:</P>
<BLOCKQUOTE>
<P>
<INPUT TYPE="hidden" NAME="kbid" value="%Y%m%d">

I have used value= 'date + "%y%m%d"'> as well but nothing works. I use the above in a cgi in the follwoing manner:


<b><font face="Verdana" size="2">KBID</font></b>: </P>$param{kbid}</font></P>

But it just prints either date + --or-- %y%m%d....  Can I use year month day in a hidden field? Please let me know how I can get the above done.

Thanks!
0
Comment
Question by:jovato
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 2

Expert Comment

by:BassTeQ
ID: 7979008
Add this code to your program

#date stuff
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$mon=$mon+1;
$year=$year+1900 if ($year >= 100);
$currdate="$mday/$mon/$year";

Then change this line
<INPUT TYPE="hidden" NAME="kbid" value="%Y%m%d">

to this
<INPUT TYPE="hidden" NAME="kbid" value="$currdate">

You can change the $currdate variable to display the date format you require.
eg
$currdate="$mday-$mon-$year";
$currdate="$mday"."$mon"."$year";
etc ...

Hope this helps!
0
 
LVL 48

Expert Comment

by:Tintin
ID: 7979124
BassTeQ.

$year=$year+1900 if ($year >= 100);

No need for the if test.

$year+=1900;  

will *always* be accurate for any dates >= 1900

Also no need to set a whole bunch of variables that aren't used in:

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;

better to do:

($mday,$mon,$year) = (localtime)[3,4,5];

And a neater way of doing the whole lot is:

use POSIX;
$date = strftime("%Y/%m/%d",localtime);


jovato.

In order to get the form to put in the date, you will need to use javascript, unless you are automatically generating the form with a language such as Perl.
0
 
LVL 2

Expert Comment

by:BassTeQ
ID: 7979178
A few good points there tintin, thats just the standard code I use for all my date/time functions, thats why I declare everything, never know when you're going to need it :)

Cheers
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7986751
$param{kbid}= '<INPUT TYPE="hidden" NAME="kbid" value="'
            . `date +"%Y%m%d"` . '">';
0
 

Expert Comment

by:amitabhrai
ID: 7988867
You can change your .html to .shtml to utilize the "server side includes" and use the following code.

<!--#config timefmt="%Y%m%d" -->

<INPUT TYPE="hidden" NAME="kbid"
value='<!--#echo var="DATE_LOCAL" -->'>
0
 

Author Comment

by:jovato
ID: 7999290
I have tried the above comments and none work. Let me add a little more:

I am bouncing this form off of a perl script. This is for a knowledgebase. All I am tring to do is automaticly make a knowledgebase number for the html document that the perl script kicks out. For example: A user enters all of the relevent data into the fields and hits submit. At that time the script takes the current date and the script uses it to create a name for the page. So when a user hits submit, the parameter kbid should be like 022320030845.html. (month day year hour minute). I just need a way to configure this either on the form itself (as a hidden field) or within the script.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8004119
> At that time the script takes the current date
does this mean that the time should be created at client side?
If so, you need JavaScript(or any anyother active scripting language).
Are you aware that such a solution might create multiple identical timestamps?
0
 

Author Comment

by:jovato
ID: 8004321
Good point. I would rather see the time be server side. Seems like it would be easier as well.
0
 

Author Comment

by:jovato
ID: 8004334
Here is the perl script:

sh-2.05$ more tester.pl
#!/usr/bin/perl

use CGI;
use CGI::Carp qw(fatalsToBrowser);


my $q = new CGI;
print $q->header;
my %param = $q->Vars;



my $template = <<"EOF";
<html>
<head>
<title>cpconfig.com KB: $param{issue}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#FF0000" vlink="#FF0000" alink="#FF
0000">
<center>
<table width="600" border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td width="600" height="550" valign="top">
      <div align="center">
        <p><b><font face="Verdana, Arial, Helvetica, sans-serif" size="4" color="#999999"><br>
        </font><font face="Fixedsys" size="6" color="#000000">cpconfig</font></b></p>
      </div>
      <div align="center">
        <b><font face="Fixedsys" size="2">KnowledgeBase</font></b></div>
      <blockquote>
        <div align="center">
          <hr>
          <font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#999999">&nbsp;|
          <a href="#">cpconfig forum</a> | <a href="#">Home</a>
          | <a href="#">Documentation</a> |
          <a href="#">FAQ</a> | <a href="#">Links</a> | <a href="#">KB Help</a> |</font><div align="left">
            <hr>
            &nbsp;
            <p>
<b><font face="Verdana" size="2">KBID</font></b>: </P>$param{kbid}</font></P>

            <font face="Verdana" size="2"><b>Issue:</b></font>
<p><font face="Verdana" size="2">$param{issue}</font></P>
            <p><font face="Verdana" size="2"><b>Version:</b></font></P>
<p><font face="Verdana" size="2">$param{version}</font></P>
            <font face="Verdana" size="2"><b>Platform:</b></font>
<p><font face="Verdana" size="2">$param{platform}</font></P>
            <p><font face="Verdana" size="2"><b>Abstract:</b></font></P>
<p><font face="Verdana" size="2">$param{abstract}</font></P>
            <font face="Verdana" size="2"><b>Solution:</b></font>
<p><font face="Verdana" size="2">$param{solution}</font></P>
            <p><font face="Verdana" size="2"><b>Links/Sources:</b></font></P>
<p><font face="Verdana" size="2">$param{links}</font></P>
            <font face="Verdana" size="2"><b>Submitted By:</b></font>
<p><font face="Verdana" size="2">$param{submitted}</font></P>
            <p>&nbsp;</p>
            <p><font face="Verdana, Arial, Helvetica, sans-serif" color="#999999" size="1"><i>
            DISCLAIMER: The
            following information is believed to be accurate. If you find
            anything wrong with any of the documentation, please e-mail us at
            <a href="mailto:docs\@cpconfig.com?subject=KnowledgeBase problems">kb\@cpconfig.com</a> and let us know. We take n
o responsibility for
            the accuracy or completeness of the documentation here. As always,
            please test everything in a lab environment and not in production.</i></font></p>
            <p>&nbsp;</p>
          </div>
        </div>
      </blockquote>
    </td>
  </tr>
</table></center>
</body>
</html>
EOF


open (FILE, ">/usr/local/apache/htdocs/knowledgebase/$param{kbid}.html")  or die "Can not open $param{kbid}.html $!\n";
print FILE $template;
close (FILE);

print "<h1>Created File</h1>";
exit;
sh-2.05$
0
 

Author Comment

by:jovato
ID: 8004344
And here is the form:

sh-2.05$ more blank_kb.htm
<html>
<head>
<title>Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--#config timefmt="%Y%m%d" -->

</head>

<body bgcolor="#FFFFFF" text="#000000" link="#FF0000" vlink="#FF0000" alink="#FF
0000">
<center>
  <table width="600" border="1" cellpadding="0" cellspacing="0">
    <tr>
      <td width="600" height="550" valign="top">
        <div align="center">
          <p><b><font face="Verdana, Arial, Helvetica, sans-serif" size="4" colo
r="#999999"><br>
          </font><font face="Fixedsys" size="6" color="#000000">cpconfig</font><
/b></p>
        </div>
        <div align="center">
          <b><font face="Fixedsys" size="2">KnowledgeBase</font></b></div>
        <blockquote>
          <div align="center">
            <hr>
            <font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#999999">&nbsp;|
            <a href="/forums/index.php">cpconfig forum</a> | <a href="/">Home</a>
            | <a href="/kbhelp.htm">Documentation</a> |
            <a href="/faq.htm">FAQ</a> | <a href="/links.htm">Links</a> | <a href="#">KB Help</a> |</font><div align="left">
              <hr>
              <P>
              <FORM METHOD="POST" ACTION="/cgi-bin/tester.pl">
<b><font face="Verdana" size="2">KBID</font></b>:</P>
<BLOCKQUOTE>
<P>
<INPUT TYPE="hidden" NAME="kbid" value='<!--#echo var="DATE_LOCAL" -->'>


<BR>
</P>
</BLOCKQUOTE>
<P>
<b><font face="Verdana" size="2">Issue</font></b>:</P>
<BLOCKQUOTE>
<P>
<TEXTAREA NAME="issue" ROWS=5 COLS=43></TEXTAREA>
<BR>
</P>
</BLOCKQUOTE>
<P>
<font face="Verdana" size="2"><b>Version</b></font>:</P>
<BLOCKQUOTE>
<P>
<INPUT TYPE=TEXT NAME="version" SIZE=51>
<BR>
</P>
</BLOCKQUOTE>
<P>
<b><font face="Verdana" size="2">Platform:</font></b></P>
<BLOCKQUOTE>
<P>
<INPUT TYPE=TEXT NAME="platform" SIZE=51>
<BR>
</P>
</BLOCKQUOTE>
<P>
<b><font face="Verdana" size="2">Abstract:</font></b></P>
<BLOCKQUOTE>
<P>
<TEXTAREA NAME="abstract" ROWS=5 COLS=44></TEXTAREA>
<BR>
</P>
</BLOCKQUOTE>
<P>
<b><font size="2" face="Verdana">Solution:</font></b></P>
<BLOCKQUOTE>
<P>
<TEXTAREA NAME="solution" ROWS=5 COLS=44></TEXTAREA>
<BR>
</P>
</BLOCKQUOTE>
<P>
<b><font size="2" face="Verdana">Links/Sources:</font></b></P>
<BLOCKQUOTE>
<P>
<TEXTAREA NAME="links" ROWS=5 COLS=44></TEXTAREA>
<BR>
</P>
</BLOCKQUOTE>
<P>
<b><font size="2" face="Verdana">Submitted By:</font></b></P>
<BLOCKQUOTE>
<P>
<INPUT TYPE=TEXT NAME="submitted" SIZE=53>
<BR>
</P>
</BLOCKQUOTE>
              <p>
<INPUT TYPE=SUBMIT VALUE="Submit Form">
<INPUT TYPE=RESET VALUE="Reset Form"> </p>
</FORM>
              <p>&nbsp;</p>
              <p><font face="Verdana, Arial, Helvetica, sans-serif" color="#999999" size="1"><i>
              DISCLAIMER: The
              following information is believed to be accurate. If you find
              anything wrong with any of the documentation, please e-mail us at
              <a href="mailto:docs@cpconfig.com?subject=KnowledgeBase problems">kb@cpconfig.com</a> and let us know. We take n
o responsibility for
              the accuracy or completeness of the documentation here. As always,
              please test everything in a lab environment and not in production.</i></font></p>
              <p>&nbsp;</p>
            </div>
          </div>
        </blockquote>
      </td>
    </tr>
  </table></center>
</body>
</html>
0
 
LVL 2

Expert Comment

by:BassTeQ
ID: 8013401
Change your perl script to be.
You can chage the date stuff with the suggestions Tintin made if you wish.


#!/usr/bin/perl

use CGI;
use CGI::Carp qw(fatalsToBrowser);

#date stuff
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$mon=$mon+1;
$year=$year+1900 if ($year >= 100);
$currdate="$mon"."$mday"."$year"."$hour"."$min";


my $q = new CGI;
print $q->header;
my %param = $q->Vars;



my $template = <<"EOF";
<html>
<head>
<title>cpconfig.com KB: $param{issue}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#FF0000" vlink="#FF0000" alink="#FF
0000">
<center>
<table width="600" border="1" cellpadding="0" cellspacing="0">
 <tr>
   <td width="600" height="550" valign="top">
     <div align="center">
       <p><b><font face="Verdana, Arial, Helvetica, sans-serif" size="4" color="#999999"><br>
       </font><font face="Fixedsys" size="6" color="#000000">cpconfig</font></b></p>
     </div>
     <div align="center">
       <b><font face="Fixedsys" size="2">KnowledgeBase</font></b></div>
     <blockquote>
       <div align="center">
         <hr>
         <font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#999999">&nbsp;|
         <a href="#">cpconfig forum</a> | <a href="#">Home</a>
         | <a href="#">Documentation</a> |
         <a href="#">FAQ</a> | <a href="#">Links</a> | <a href="#">KB Help</a> |</font><div align="left">
           <hr>
           &nbsp;
           <p>
<b><font face="Verdana" size="2">KBID</font></b>: </P>$param{kbid}</font></P>

           <font face="Verdana" size="2"><b>Issue:</b></font>
<p><font face="Verdana" size="2">$param{issue}</font></P>
           <p><font face="Verdana" size="2"><b>Version:</b></font></P>
<p><font face="Verdana" size="2">$param{version}</font></P>
           <font face="Verdana" size="2"><b>Platform:</b></font>
<p><font face="Verdana" size="2">$param{platform}</font></P>
           <p><font face="Verdana" size="2"><b>Abstract:</b></font></P>
<p><font face="Verdana" size="2">$param{abstract}</font></P>
           <font face="Verdana" size="2"><b>Solution:</b></font>
<p><font face="Verdana" size="2">$param{solution}</font></P>
           <p><font face="Verdana" size="2"><b>Links/Sources:</b></font></P>
<p><font face="Verdana" size="2">$param{links}</font></P>
           <font face="Verdana" size="2"><b>Submitted By:</b></font>
<p><font face="Verdana" size="2">$param{submitted}</font></P>
           <p>&nbsp;</p>
           <p><font face="Verdana, Arial, Helvetica, sans-serif" color="#999999" size="1"><i>
           DISCLAIMER: The
           following information is believed to be accurate. If you find
           anything wrong with any of the documentation, please e-mail us at
           <a href="mailto:docs\@cpconfig.com?subject=KnowledgeBase problems">kb\@cpconfig.com</a> and let us know. We take n
o responsibility for
           the accuracy or completeness of the documentation here. As always,
           please test everything in a lab environment and not in production.</i></font></p>
           <p>&nbsp;</p>
         </div>
       </div>
     </blockquote>
   </td>
 </tr>
</table></center>
</body>
</html>
EOF


open (FILE, ">/usr/local/apache/htdocs/knowledgebase/$currdate.html")  or die "Can not open $currdate.html $!\n";
print FILE $template;
close (FILE);

print "<h1>Created File</h1>";
exit;
0
 

Author Comment

by:jovato
ID: 8013446
BassTeQ,

I made the changes above, but the files are being saved as $currdate.html. The script modifiactions are exactly as you specified. Can you think of any reason this wouldn't work?
0
 
LVL 48

Accepted Solution

by:
Tintin earned 400 total points
ID: 8013875
The only reason you would get a file literally called $currdate.html is if you used single quotes on the open.  

Make sure you use double quotes.

BTW, a shorter way of obtaining the date is:

use POSIX;
$currdate = strftime("%Y%m%d%H%M",localtime);
0
 

Author Comment

by:jovato
ID: 8021224
That was the ticket.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question