EditAssetForm: use datetime-local input type for date captured field

This commit is contained in:
Aaron van Geffen 2023-11-12 17:14:30 +01:00
parent b48dd324cd
commit 44c6bf5914
2 changed files with 7 additions and 3 deletions

View File

@ -42,7 +42,8 @@ class EditAsset extends HTMLController
// Key info // Key info
if (isset($_POST['title'], $_POST['slug'], $_POST['date_captured'], $_POST['priority'])) if (isset($_POST['title'], $_POST['slug'], $_POST['date_captured'], $_POST['priority']))
{ {
$date_captured = !empty($_POST['date_captured']) ? new DateTime($_POST['date_captured']) : null; $date_captured = !empty($_POST['date_captured']) ?
new DateTime(str_replace('T', ' ', $_POST['date_captured'])) : null;
$slug = strtr($_POST['slug'], [' ' => '-', '--' => '-', '&' => 'and', '=>' => '', "'" => "", ":"=> "", '\\' => '-']); $slug = strtr($_POST['slug'], [' ' => '-', '--' => '-', '&' => 'and', '=>' => '', "'" => "", ":"=> "", '\\' => '-']);
$asset->setKeyData(htmlspecialchars($_POST['title']), $slug, $date_captured, intval($_POST['priority'])); $asset->setKeyData(htmlspecialchars($_POST['title']), $slug, $date_captured, intval($_POST['priority']));
} }
@ -50,9 +51,11 @@ class EditAsset extends HTMLController
// Handle tags // Handle tags
$new_tags = []; $new_tags = [];
if (isset($_POST['tag']) && is_array($_POST['tag'])) if (isset($_POST['tag']) && is_array($_POST['tag']))
{
foreach ($_POST['tag'] as $id_tag => $bool) foreach ($_POST['tag'] as $id_tag => $bool)
if (is_numeric($id_tag)) if (is_numeric($id_tag))
$new_tags[] = $id_tag; $new_tags[] = $id_tag;
}
$current_tags = array_keys($asset->getTags()); $current_tags = array_keys($asset->getTags());

View File

@ -82,8 +82,9 @@ class EditAssetForm extends Template
<div class="row mb-2"> <div class="row mb-2">
<label class="col-form-label col-sm-3">Date captured:</label> <label class="col-form-label col-sm-3">Date captured:</label>
<div class="col-sm"> <div class="col-sm">
<input class="form-control" name="date_captured" size="30" value="', <input class="form-control" type="datetime-local" step="1"
$date_captured ? $date_captured->format('Y-m-d H:i:s') : '', '" placeholder="Y-m-d H:i:s"> name="date_captured" size="30" placeholder="Y-m-d H:i:s" value="',
$date_captured ? $date_captured->format('Y-m-d H:i:s') : '', '">
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">