fill title with filename when uploading

This commit is contained in:
Tomáš Mládek 2019-05-05 13:08:55 +02:00
parent d7b9df6733
commit 7d12954372

View file

@ -1,7 +1,8 @@
<div class="text document edit-form">
<form method="post" id="form" action="admin.php?action=edit_item<?= empty($doc) ? "" : "&item=" . $doc["ID"] ?>"
enctype="multipart/form-data">
<strong>Title:</strong> <input type="text" name="Title" value="<?= empty($doc) ? "" : $doc["Title"] ?>"><br>
<strong>Title:</strong> <input id="title-input" type="text" name="Title"
value="<?= empty($doc) ? "" : $doc["Title"] ?>"><br>
<strong>Author:</strong> <input type="text" name="Author" value="<?= empty($doc) ? "" : $doc["Author"] ?>"><br>
<strong>Date published:</strong> <input type="text" name="Published"
value="<?= empty($doc) ? "" : $doc["Published"] ?>"><br>
@ -9,7 +10,7 @@
<textarea name="Description" cols="120" rows="20">
<?= empty($doc) ? "" : $doc["Description"] ?>
</textarea><br>
<strong>File:</strong> <input type="file" name="upfile"><br>
<strong>File:</strong> <input id="file-input" type="file" name="upfile" onchange="updateTitle()"><br>
<strong>URL:</strong> <input type="text" name="URL" value="<?= empty($doc) ? "" : $doc["URL"] ?>"><br>
<strong>Tags:</strong> <input type="text" name="Tags" value="<?php
if (!empty($doc)) {
@ -25,3 +26,12 @@
<input type="submit">
</form>
</div>
<script>
function updateTitle() {
const titleInput = document.getElementById("title-input");
if (titleInput.value.length === 0) {
const filename = document.getElementById("file-input").value;
titleInput.value = filename.replace(/.*[\/\\]/, '').replace(/\.[\w]{2,}$/, '');
}
}
</script>