Pre-populate date form

Hi,
I am trying to pre-populate a date form with $date. I can echo $date to the html page inside php tags fine, can’t use the variable $date in the date form itself.

Here is part of the html,

<?php echo($date); ?>
       <form action="?<?php htmlout($action); ?>" method="post">
               <input type="submit" value="<?php htmlout($button); ?>">
               <p>Input date in form: <small>YYYY-MM-DD</small> <input type="date" name="date" <?php echo($date); ?> > <?php if (isset($_GET['setupNotes'])): ?><small>(Leave blank for todays date)</small></p><?php endif; ?>
           <table>
            <tr>

Here is an image of the html page and you can see that the date is being echoed fine.

Any help greatly appreciated,
Thanks,
Shane

<?php
$date = '03/18/2015';
$today = date('m/d/Y', strtotime("Now"));

?>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post">
	<input type="datetime" name="date" value="<?php echo ($date !== $today) ? $date : NULL; ?>">
</form>
</body>
</html>

Don’t know exactly what you’re trying to do, but maybe something like the above will help you.

Hi,
Thanks for your reply.

The date variable is set in my controller file index.php to 1978-03-19 and I can echo it in the html file, but can’t get it to pre-populate the date form.

Thanks,
Shane

Yes it is working now. I had to set

value = "<?php echo($date): ?>"

as in,

   <form action="?<?php htmlout($action); ?>" method="post">
           <input type="submit" value="<?php htmlout($button); ?>">
           <p>Input date in form: <small>YYYY-MM-DD</small> <input type="date" name="date" value = "<?php echo($date); ?>" > <?php if (isset($_GET['setupNotes'])): ?><small>(Leave blank for todays date)</small></p><?php endif; ?>
       <table>

Thanks,
Shane

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.