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
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).

 

Link to comment
Share on other sites

Looks like you are trying to do this in HTML, try this instead

 

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

 

If this is PHP and not HTML, the post the code around it and not just a snippet.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.