Jump to content

Insert current date into a form


jeff5656

Recommended Posts

In a form, I want the current date to be in the date field as a default (but the user can delete that and enter their own if they want).  The following was tried but date is not display when I run the script

 

<php

 

$current_date = date (M j y);

[.... snip some code here such as creting the form, etc.]

 

<th scope="col"><div align="left">Date of consult: </div></th>

      <th scope="col"><div align="left">

        <input type="text" name="$current_date" />

 

Now I tried that with and without the $ sign.

Thank you.  Will display more code if you need it, but the form itself comes aftrer the <html> and <form> but the ?> is at the very end of the whole thing...

Link to comment
https://forums.phpfreaks.com/topic/94541-insert-current-date-into-a-form/
Share on other sites

I couldnt edit my post I meant this:

 

$current_date = date ("M j y");

 

        <input type="text" name="current_date" value="$current_date" />

 

but this also does not work:

        <input type="text" name="current_date" value="current_date" />

 

(they just dump that specific text into the field).

 

if you are putting the input outside of php tags then use this

 

 <input type=text name="current_date" value="<?php echo $current_date; ?>" />

 

if you are inside php tags then this

<?php
echo "<input type=text name=\"current_date\" value=\"".$current_date."\" />
?>

 

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.