-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.html
More file actions
227 lines (208 loc) · 8.05 KB
/
Copy pathform.html
File metadata and controls
227 lines (208 loc) · 8.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Recipe</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 80%;
max-width: 600px;
}
h1 {
margin-top: 0px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input,
.form-group textarea,
.form-group select {
width: 100%;
padding: 8px;
border-radius: 4px;
border: 1px solid #ddd;
box-sizing: border-box;
max-width: 100%;
}
.form-group textarea {
height: 100px;
}
.form-group button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
}
.form-group button:hover {
background-color: #0056b3;
}
.error {
color: red;
font-size: 0.875em;
}
.stars_container{
height: 50px;
display: flex;
gap: 5px;
}
.fa-star{
font-size: 1.5rem;
color:orange;
}
.fa-star:hover{
cursor: pointer;
}
.selected{
font-weight: 900;
}
</style>
</head>
<body>
<div class="container">
<center><h1>Add New Recipe</h1></center>
<form id="recipeForm">
<div class="form-group">
<label for="recipeName">Recipe Name:</label>
<input type="text" id="recipeName" name="recipeName" required>
<div class="error" id="nameError"></div>
</div>
<div class="form-group">
<label for="imageURL">Image URL:</label>
<input type="url" id="imageURL" name="imageURL" required>
<div class="error" id="imageURLError"></div>
</div>
<div class="form-group">
<label for="stars">Stars (1-5):</label>
<div class="stars_container">
<div class="star" onclick="rate(1)"><i class="fa-regular fa-star"></i></div>
<div class="star" onclick="rate(2)"><i class="fa-regular fa-star"></i></div>
<div class="star" onclick="rate(3)"><i class="fa-regular fa-star"></i></div>
<div class="star" onclick="rate(4)"><i class="fa-regular fa-star"></i></div>
<div class="star" onclick="rate(5)"><i class="fa-regular fa-star"></i></div>
</div>
<input type="hidden" id="stars" name="stars" required>
<div class="error" id="starsError"></div>
</div>
<div class="form-group">
<label for="category">Category:</label>
<select id="category" name="category">
<option value="" selected>Select category</option>
<option value="appetizer">Appetizer</option>
<option value="main_course">Main Course</option>
<option value="dessert">Dessert</option>
<option value="beverage">Beverage</option>
</select>
<div class="error" id="categoryError"></div>
</div>
<div class="form-group">
<label for="ingredients">Ingredients:</label>
<textarea id="ingredients" name="ingredients" required></textarea>
<div class="error" id="ingredientsError"></div>
</div>
<div class="form-group">
<label for="process">Process:</label>
<textarea id="process" name="process" required></textarea>
<div class="error" id="processError"></div>
</div>
<div class="form-group">
<label for="videoURL">Video URL:</label>
<input type="url" id="videoURL" name="videoURL">
<div class="error" id="videoURLError"></div>
</div>
<div class="form-group">
<button type="submit">Add Recipe</button>
</div>
</form>
</div>
<script>
document.getElementById('recipeForm').addEventListener('submit', function(event) {
document.querySelectorAll('.error').forEach(el => el.textContent = '');
let valid = true;
const name = document.getElementById('recipeName').value.trim();
const imageURL = document.getElementById('imageURL').value.trim();
const stars = parseInt(document.getElementById('stars').value, 10);
const ingredients = document.getElementById('ingredients').value.trim();
const process = document.getElementById('process').value.trim();
const videoURL = document.getElementById('videoURL').value.trim();
const category = document.getElementById('category').value;
if (!name) {
document.getElementById('nameError').textContent = 'Recipe name is required.';
valid = false;
}
if (!imageURL) {
document.getElementById('imageURLError').textContent = 'Image URL is required.';
valid = false;
}
if (isNaN(stars) || stars < 1 || stars > 5) {
document.getElementById('starsError').textContent = 'Stars must be between 1 and 5.';
valid = false;
}
if (!ingredients) {
document.getElementById('ingredientsError').textContent = 'Ingredients are required.';
valid = false;
}
if (!process) {
document.getElementById('processError').textContent = 'Process is required.';
valid = false;
}
if (videoURL && !/^https?:\/\/.+/.test(videoURL)) {
document.getElementById('videoURLError').textContent = 'Invalid video URL.';
valid = false;
}
if (!category) {
document.getElementById('categoryError').textContent = 'Category is required.';
valid = false;
}
if (valid) {
const recipe = {
name: name,
imageURL: imageURL,
stars: stars,
ingredients: ingredients,
process: process,
videoURL: videoURL,
category: category
};
console.log('Recipe added:', recipe);
}
else{
event.preventDefault();
}
});
const rate = (n) =>{
var stars = document.getElementsByClassName("fa-star");
for (let i = 0; i < stars.length; i++) {
if(i < n){
stars[i].classList.remove('fa-regular');
stars[i].classList.add('fa-solid', 'selected');
}
else{
stars[i].classList.remove('fa-solid', 'selected');
stars[i].classList.add("fa-regular");
}
}
document.getElementById('stars').value = n;
}
</script>
</body>
</html>