Skip to content

Commit

Permalink
git commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-peter-kamvabingu committed Dec 6, 2024
1 parent a1d6b1c commit 9b6bc48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
42 changes: 13 additions & 29 deletions contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,21 @@ <h3>Follow Us | Talk with Us</h3>
</div>
<div class="col-1">
<div class="contact-form">
<form action="process_form.php" method="POST" novalidate>
<!-- Name Input -->
<div class="form-group">
<input type="text" class="contact-input c-name" name="name" placeholder="Name (*)" required>
<div class="invalid-feedback f-name" style="display: none;">*Please, enter your name</div>
</div>

<!-- Phone Input -->
<div class="form-group">
<input type="text" class="contact-input c-phone" name="phone" placeholder="Phone (*)" required>
<div class="invalid-feedback f-phone" style="display: none;">*Please enter a valid phone number</div>
</div>

<!-- Email Input -->
<div class="form-group">
<input type="email" class="contact-input c-email" name="email" placeholder="E-mail (*)" required>
<div class="invalid-feedback f-email" style="display: none;">*Please, enter your E-mail</div>
</div>

<!-- Message Input -->
<div class="form-group">
<textarea class="contact-input c-message" name="message" placeholder="Message (*)" required></textarea>
<div class="invalid-feedback f-message" style="display: none;">*Please, enter your message</div>
</div>

<!-- Submit Button -->
<div class="form-group">
<input type="submit" class="send-btn" value="Send Message">
</div>
<form action="process_form.php" method="POST">
<input type="text" class="contact-input c-name" name="name" placeholder="Name (*)" required>
<div class="invalid-feedback f-name" style="display: none;">*Please, enter your name</div>

<input type="text" class="contact-input c-phone" name="phone" placeholder="Phone (*)" required>
<div class="invalid-feedback f-phone" style="display: none;">*Please enter your phone number</div>

<input type="email" class="contact-input c-email" name="email" placeholder="E-mail (*)" required>
<div class="invalid-feedback f-email" style="display: none;">*Please, enter your E-mail</div>

<textarea class="contact-input c-message" name="message" placeholder="Message (*)" required></textarea>
<input type="submit" class="send-btn" value="Send Message">
</form>



</div>
</div>
Expand Down
9 changes: 4 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ document.querySelector('form').addEventListener('submit', function (e) {
const email = document.querySelector('.c-email').value.trim();
const message = document.querySelector('.c-message').value.trim();

// Error messages
// Error message elements
const messageName = document.querySelector('.f-name');
const messagePhone = document.querySelector('.f-phone');
const messageEmail = document.querySelector('.f-email');

// Validation Functions
const isEmail = (mail) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(mail); // Simple email regex
const isEmail = (mail) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(mail); // Basic email format
const isName = (name) => /^[a-zA-Z\s]+$/.test(name); // Matches letters and spaces
const isPhoneNumber = (number) => /^\d+$/.test(number); // Matches any numeric value

let isValid = true;

Expand All @@ -27,8 +26,8 @@ document.querySelector('form').addEventListener('submit', function (e) {
messageName.style.display = 'none';
}

// Phone Validation (Any numeric phone number)
if (!isPhoneNumber(phone)) {
// Phone Validation (No restrictions)
if (!phone) { // Only check if the phone field is empty
messagePhone.style.display = 'block';
isValid = false;
} else {
Expand Down

0 comments on commit 9b6bc48

Please sign in to comment.