Is the Bootstrap code in contact_me.php verifying if the checkbox has been selected?

I need assistance with integrating a checkbox into my basic contact form. I want the validation to ensure that the checkbox is checked before allowing the form to be submitted. Any help on this matter would be greatly appreciated.

FORM:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqBootstrapValidation/1.3.7/jqBootstrapValidation.min.js" ></script>

    <form id="contactForm" name="sentMessage" novalidate="">
    <div class="control-group form-group">
    <div class="controls"><label>Name:</label> <input id="name" class="form-control" required="" type="text" data-validation-required-message="Please enter your name." />
    <p class="help-block"> </p>
    </div>
    </div>
    <div class="control-group form-group">
    <div class="controls"><label>Phone Number:</label> <input id="phone" class="form-control" required="" type="tel" data-validation-required-message="Please enter a phone number." />
    <div class="help-block"> </div>
    </div>
    </div>
    <div class="control-group form-group">
    <div class="controls"><label>Email:</label> <input id="email" class="form-control" required="" type="email" data-validation-required-message="Please enter an email address." />
    <div class="help-block"> </div>
    </div>
    </div>
    <div class="control-group form-group">
    <div class="controls"><label>Message:</label> <textarea id="message" class="form-control" style="resize: none;" cols="100" maxlength="999" required="" rows="10" data-validation-required-message="Write a message"></textarea>
    <div class="help-block"> </div>
    </div>
    </div>


<div class="control-group form-group">
<div class="controls">
      <input class="form-check-input" type="checkbox" value="1" id="privacy" required="" data-validation-required-message="Check this box to proceed" />
      <label class="form-check-label" for="privacy">
        Agree to terms and conditions
      </label>
<div class="help-block"> </div>
    </div>
  </div>



    <div id="success"> </div>
    <!-- For success/fail messages --> <button id="sendMessageButton" class="btn btn-success" type="submit">Send Message</button></form>

contact_me.js:

contact_me.php:

The form functions correctly, but when attempting to validate if a checkbox is selected, the validation process fails. Despite various trials, I have yet to find a suitable solution.

Answer №1

In my initial question, I forgot to mention that I was using jqBootstrapValidation. So now I have included the necessary scripts in the question. Additionally, I have managed to find a solution that works with this specific code snippet for the checkbox. :-)

<div class="control-group">
                            <div class="controls">
                                <label class="checkbox">
                                    <input type="checkbox" id="terms-and-conditions" name="terms-and-conditions" required="" data-validation-required-message="Check this box if you want to continue" aria-invalid="false">
                                    By checking this box, you agree to our <!-- START: Modals --><a href="/privacy-policy?lang=1" class="modal_link" data-modal-class-name="no_title">privacy policy</a><!-- END: Modals -->.
                                </label>
                                <p class="help-block"></p>
                            </div>
                        </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Orthographic Mode with EDL Shader in Potree Viewer

Struggling with the EDL Shader in the Potree Viewer? While it performs well in perspective mode, I'm encountering issues when trying to utilize orthographic mode for my project. Check out the accompanying GIF and example below for reference. The ED ...

Issue with deploying NEXT.JS due to a failure in the build process caused by next lint

Issue I have been encountering deployment failures on Vercel due to lint errors in test files within my git repository. Despite following the recommendations from the Vercel documentation for ESLint settings, the issue persists. According to Vercel' ...

Step-by-step guide on discovering an object with an ID that is not present in a separate array

I have 2 arrays of objects. One array is the original array, and the other array contains the modified array. The modified array can include new objects, edited objects, or deleted objects in the settingValueDtoList. Currently, I am working on writing cod ...

Toggle divs by using a checkbox (Vue.js)

On my authentication page, I have implemented a checkbox that I want to use to toggle between Sign Up and Sign In forms. When the checkbox is clicked, it should display the Sign Up form, and when it's unchecked, it should show the Sign In form. I fou ...

JSON data not displaying correctly in bootstrap table

I've been grappling with this issue for hours now, but I'm struggling to get my bootstrap table populated correctly. Here's the snippet of my HTML: <html> <head> <link rel="stylesheet" href="https://code.jquery.com/ui/1.1 ...

Inquiry into the use of Jquery.ajax()

Hey there, I'm curious about using Jquery Ajax to retrieve a numeric value from a website. Any suggestions on where I should begin? Any advice would be greatly appreciated. Thanks in advance! Best regards, SWIFT ...

Detecting browser reload in React/Typescript: A guide

Is there a way to determine if the browser has been reloaded? I've explored various solutions, but most suggest using code like this: const typeOfNavigation = (performance.getEntriesByType("navigation")[0] as PerformanceNavigationTiming).type ...

"Utilizing Bootstrap's form-check feature places the checkbox alongside the text

While attempting to create a checkbox using the Bootstrap form-check class, I encountered an issue with my code. Here is the snippet: <form> <div class="form-section"> <div>Title</div> <div class="form-check"> ...

JavaScript's dependency injection functionality is ineffective

I am looking to create a function named createCoffee which will take a function argument called knowHow. function createCoffee(knowHow){ var x=new knowHow(coffee,beans,milk,sugar); knowHow.create(); } This will allow me to use different knowHow funct ...

Combining Javascript and Django for a powerful web development solution

Having trouble setting up JS on my Django web app, despite reading through the documentation and previous queries. Using the Django dev server with the following file structure: mysite/ __init__.py MySiteDB manage.py settings.py ...

Exploring ways to capture all console outputs or retrieve the current console content in frontend development

Currently working with Angular and looking to integrate a bug reporting feature into my application. I want to capture the content of the browser's console for debugging purposes. However, I'm unsure of how to access it. Not all errors are logge ...

Combine two entities to create a new entity that mirrors the structure of the first entity

Can someone assist me with a data structure issue? Here are the objects I am working with: const elements = { item1: {color: 'blue', name: 'Item One' }, item2: {color: 'green', name: 'Item Two' }, item3: {colo ...

Add multiple images to various div containers

I am facing a challenge with my code as I am trying to upload and display two different files inside of two different divs using two buttons. Currently, my code is only working for one image. How can I modify the code to handle two images successfully? Any ...

Are there any options available for customizing the animation settings on the UI-bootstrap's carousel feature?

If you're interested in seeing an example of the standard configuration, check out this link. It's surprising how scarce the documentation is for many of the features that the UIB team has developed... I'm curious if anyone here has experie ...

Overlaying a Bootstrap Collapse onto an element

I have been working with Bootstrap 3 to create a responsive website, specifically focusing on my "portfolio." You can view the website and also see an interesting error by visiting this link: If you scroll down to the section labeled "Our models" and cli ...

Not all elements of an array are returned by an arrow function with conditionals

My array looks like this: var arr = ['one', 'two', ['three', 'four']]; When attempting to use arrow functions to return each element, the third element shows up as undefined instead of the actual values. I've t ...

Gradually vanishing words while they glide across the screen

I want to achieve a similar effect seen in the game A Dark Room. The text in the game serves two purposes which I am trying to replicate: The new text is added above the old text instead of below it, pushing the older text down the page as the game progr ...

Animating the scale of multiple objects in Three.js allows for dynamic and engaging visual

Hi there! I am new to three.js and currently going through various tutorials to master the art of animating 3D objects using three.js. As a result, you may find some parts of the code below to be familiar. My objective: I am looking for a way to gradually ...

Troubleshooting AJAX Problems in ASP.NET and C#

I am currently working on implementing a WebMethod call in my C# code behind using AJAX. I have a Bootstrap Modal that should be displayed when a linkbutton is clicked, triggering the execution of the WebMethod through AJAX to populate a table in the modal ...

Encountered a connection error in the Spring Boot application: net::ERR_CONNECTION_REF

Currently working on a school project developing a Spring Boot application using Restful. The application runs smoothly locally, but when deployed to AWS, I am encountering an "net::ERR_CONNECTION_REFUSED" error for all my GET and POST requests sent to the ...