-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
125 lines (113 loc) · 4.61 KB
/
Copy pathindex.html
File metadata and controls
125 lines (113 loc) · 4.61 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic User Contact Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.contact-group {
margin-bottom: 20px;
}
.contact-group label {
font-weight: bold;
}
.dynamic-fields {
margin-top: 10px;
}
.dynamic-fields .field-row {
display: flex;
gap: 10px;
margin-bottom: 10px;
}
.dynamic-fields input {
flex: 1;
}
.dynamic-fields button {
padding: 5px 10px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Dynamic User Contact Form</h1>
<form id="userContactForm" action="" method="post" enctype="multipart/form-data">
<!-- Internal User Contacts -->
<div class="contact-group">
<label>Internal User Contacts:</label>
<div id="internalUserFields" class="dynamic-fields">
<div class="field-row">
<input type="text" name="internalName[]" placeholder="Name" required>
<input type="email" name="internalEmail[]" placeholder="Email" required>
<input type="text" name="internalContact[]" placeholder="Contact Number" required>
<button type="button" onclick="addField('internalUserFields')">+</button>
</div>
</div>
</div>
<!-- External User Contacts -->
<div class="contact-group">
<label>External User Contacts:</label>
<div id="externalUserFields" class="dynamic-fields">
<div class="field-row">
<input type="text" name="externalName[]" placeholder="Name" required>
<input type="email" name="externalEmail[]" placeholder="Email" required>
<input type="text" name="externalContact[]" placeholder="Contact Number" required>
<button type="button" onclick="addField('externalUserFields')">+</button>
</div>
</div>
</div>
<!-- File Attachment -->
<div class="contact-group">
<label>Attach Documents:</label>
<input type="file" name="documents[]" multiple required>
</div>
<!-- Dropdown for Department -->
<div class="contact-group">
<label>Department:</label>
<select name="department" id="department" required>
<option value="">Select Department</option>
<option value="legal">Legal</option>
<option value="it">Information Technology</option>
</select>
</div>
<!-- Submit Button -->
<button type="submit">Submit</button>
</form>
<script>
function addField(containerId) {
const container = document.getElementById(containerId);
const newFieldRow = document.createElement('div');
newFieldRow.classList.add('field-row');
newFieldRow.innerHTML = `
<input type="text" name="${containerId === 'internalUserFields' ? 'internalName[]' : 'externalName[]'}" placeholder="Name" required>
<input type="email" name="${containerId === 'internalUserFields' ? 'internalEmail[]' : 'externalEmail[]'}" placeholder="Email" required>
<input type="text" name="${containerId === 'internalUserFields' ? 'internalContact[]' : 'externalContact[]'}" placeholder="Contact Number" required>
<button type="button" onclick="removeField(this)">-</button>
`;
container.appendChild(newFieldRow);
}
function removeField(button) {
const fieldRow = button.parentElement;
fieldRow.remove();
}
document.getElementById('userContactForm').addEventListener('submit', function (event) {
event.preventDefault();
const department = document.getElementById('department').value;
let email = '';
if (department === 'legal') {
email = 'A.rehbein@cosnova.com';
} else if (department === 'it') {
email = 'c.miranda@cosnova.com';
} else {
alert('Please select a department.');
return;
}
alert(`Form will be sent to ${email}`);
// Additional code can be added here to handle actual form submission.
});
</script>
</body>
</html>