To give a more professional form and design to the HTML upload form template, you can utilize more advanced CSS styling techniques, incorporate a modern CSS framework like Bootstrap, add icons, include client-side validation feedback, and ensure that the design is responsive. Here's an updated version of the template with these considerations:
First, include Bootstrap CDN in the <head>:
<!-- templates/upload_form.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Image</title>
<!-- Include Bootstrap CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles -->
<style>
.container {
padding-top: 50px;
}
.custom-file-label::after {
content: "Browse";
}
.btn-upload {
margin-top: 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 4px;
}
.btn-upload:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1 class="mb-4">Upload Image</h1>
<form action="/process_image" method="post" enctype="multipart/form-data">
<div class="custom-file mb-3">
<input type="file" class="custom-file-input" id="customFile" name="file" accept="image/*" required>
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
<div class="form-group">
<label for="model">Choose a model:</label>
<select class="form-control" name="model" id="model" required>
{% for model_name in model_names %}
<option value="{{ model_name }}">{{ model_name }}</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-upload">Upload</button>
</form>
</div>
<!-- Include Bootstrap JS and its dependencies -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.9.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script>
// Bootstrap custom file input label update
$('.custom-file-input').on('change', function() {
let fileName = $(this).val().split('\\').pop();
$(this).next('.custom-file-label').addClass("selected").text(fileName);
});
</script>
</body>
</html>
The template now includes:
- Bootstrap's CSS for styling.
- A container for centering the content and adding padding at the top.
- A
custom-file class for better styling of the file input.
- A
custom-file-label class to customize the file label.
- A
form-control class for the dropdown to match with Bootstrap's styling.
- A
btn class with additional btn-upload class for button styling, matching Bootstrap's button styles with custom colors.
- A script at the bottom for Bootstrap's JavaScript and to handle display of the file name when a file is selected.
Note: Don't forget to replace model_names with the actual server-side template syntax for your specific templating language (e.g., Django, Jinja2, etc.). This setup assumes you're using Bootstrap 4.5. Adjust the Bootstrap version or local styles according to your project's requirements. Always make sure that external resources are allowed and appropriately secured in your production environment.