I have implemented a basic form in my template that already has validation. My main issue is how to check when the user clicks on the button after filling out all required fields?
<section class="contact-area pb-80" style="margin-top:10%">
<div class="container">
<div class="section-title">
<h2>Your Information</h2>
<div class="bar"></div>
<p>Please provide accurate information so we can contact you accordingly.</p>
</div>
<div class="row h-100 justify-content-center align-items-center">
<div class="col-lg-6 col-md-12">
<img src="assets/img/1.png" alt="image">
</div>
<div class="col-lg-6 col-md-12">
<form id="contactForm">
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" required placeholder="Enter your name">
</div>
</div>
<div class="col-lg-12 col-md-12">
<div class="form-group">
<input type="email" name="email" id="email" class="form-control" required placeholder="Enter your email">
</div>
</div>
<div class="col-lg-12 col-md-6">
<div class="form-group">
<input type="text" name="phone_number" id="phone_number" required class="form-control" placeholder="Enter your number (Whats app)">
</div>
</div>
<div class="col-lg-12 col-md-6">
<div class="form-group">
<input type="text" name="msg_subject" id="msg_subject" class="form-control" required placeholder="Enter your skype name">
</div>
</div>
<div class="col-lg-12 col-md-12">
<button type="submit" class="btn btn-primary">Send Message</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
My challenge lies in determining how to trigger the function I created, submit()
, only when all form fields are filled before the user clicks on the Send Message
button.
The current approach I've attempted involved adding (click)="submit()"
to the button. However, this causes the function to be called every time the button is clicked. I specifically need it to execute only when all required fields are completed.