Is there a way for me to implement a submission counter for forms?

Hello! I am currently developing a pledge page and I have a question about incorporating a counter that updates each time a user submits the form. I would like it to display something similar to this:

[ Thank you for committing to take the pledge. Currently, there have been 5 pledges made.]

Furthermore, if another individual submits the form, I want the counter to increase by 1.

Thank you to all who participate! <3

Answer №1

To achieve the desired functionality, you can include the following PHP code on the same page as your javascript/html. It is important to ensure that this code is placed above all html content.

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $counter = isset($_POST['counter']) ? $_POST['counter'] : 0;
    if(isset($_POST["button"])){
        $counter++;
        echo $counter;
    }
}

This code serves as a button click counter, incrementing every time a button is clicked. This will effectively track the number of button clicks when a form is submitted.

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

Using the power of jQuery to load Ajax content, unfortunately, the content remains

Hey there, I'm currently working with an HTML file that utilizes AJAX to load content from other HTML files on the same server. However, for some reason, it's not functioning properly. I'm new to AJAX and I'm not sure what could be caus ...

How to Perfectly Align a Div (Form) in Bootstrap 4

As I delve into the realm of Bootstrap, I am faced with a challenge in centering a form on my webpage. I have utilized CSS styling to ensure that both the html and body tags span 100% of the page's height. Additionally, I have created two divs: one ou ...

Discover the ultimate guide on developing a personalized file management system using the powerful node.js platform!

I have undertaken a rather ambitious project for myself. There exists a comprehensive tutorial on the website that outlines the process of establishing an online environment (resembling a user panel) where registered users can effortlessly upload various ...

Tips for displaying an array of objects in a single <li> tag in React

I have an array with nested arrays structured like this: [Array(2), Array(2), ...] example Each subarray contains two objects with a "text" property. obj = {key: something, text: something} Now I am looking to render the "text" property of each subarra ...

Transitioning smoothly from one specific location to another through a scrolling motion

Imagine having a box that is currently off from its correct position due to tranform:translateX(-200px) https://i.sstatic.net/2Mgwm.jpg Just below the picture, there are two <section>'s displayed - one as a large grey box and the other as a whi ...

Checkbox not working in Chrome [Version 101.0.4951.41 (Official Build) (64-bit)]

Update: It appears that the checkboxes in my project are not functioning correctly. Even when a standard checkbox was added to the HTML, it failed to respond to click events. I am currently developing a dat.gui menu for my THREE.JS project. You can find ...

A guide on effectively mocking a Vuex store within the parentComponent of VueJS test-utils

I am currently using Jest in conjunction with vue-test-utils to test the reaction of a child component to an $emit event triggered by the parent component. The VueJS test-utils library offers a parentComponent option that can be utilized when mounting or ...

Getting response headers from an AJAX POST requestWould you like to know how to

I am having trouble retrieving response headers sent by the server. Despite being able to view the response headers in Chrome Dev Tools, when trying to access them using JavaScript, I am only getting an empty object. (I am utilizing the isomorphic-fetch l ...

PHP redirect malfunctioning, yet still functioning?

After making some changes to the structure of my website, I seem to have broken the script somehow. When a user fills out a form correctly, they should be redirected to the appropriate page. However, the page just hangs. Strangely, the form works fine when ...

How can you customize the default select box in a Django template using a passed parameter?

I have a situation where I am passing a dictionary to a Django template and need to set a default value for a select box. The context is that this template serves as an 'edit product' page for a previous 'add product' form. When the use ...

Encountering difficulties in targeting a JavaScript generated button within an array using a function, resulting in an error message that reads "Unable to read property 'setAttribute' of null"

Trying to change the background of a specific button when clicking on it is proving to be quite the challenge for me. I created an array of 100 buttons (with the intention of developing a simple game later) using a for loop, giving each button a unique id ...

Retrieving values from a jQuery object array using keys rather than array indices

I am facing a challenge where I need to extract values from an object returned through $.post, but the order of the arrays can vary. Therefore, I must retrieve them based on their keys which are nested inside the array. An example is provided below. { Id: ...

The output of JSON.stringify() when given a single value as input

The JSON.stringify() function is designed to convert a JavaScript value into JSON format. console.log(JSON.stringify('a')); //output: "a" console.log(JSON.stringify(1)); //output: 1 console.log(JSON.stringify(true)); //output: true However, tec ...

Issue with JQuery causing Google map to partially load

Trying to incorporate GoogleMap into a hash page within my project has been a bit challenging. When transitioning from one page to the map page, the GoogleMap only loads partially. Interestingly, upon refreshing the hash page, it loads successfully. The fu ...

Why is the appsecret_proof invalid?

Currently, I am in the process of developing a new application. I am utilizing the Javascript API for logging in (v2.4) and the latest version of the PHP API (v5). To test the functionality of my app, I have created a Test App. With the Javascript API, I h ...

Selecting multiple options on a mobile device

I'm facing an issue that seems quite unusual. I created a multiple select form using bootstrap. On the mobile version through the browser console, all the information is being displayed correctly (screen1). However, when I try it on an actual mobile d ...

Implementing dynamic ng-forms with real-time validation

My directive includes a template with an ng-form: <ng-form name="autocompleteForm"> <div class="form-group" show-errors> <input type="text" class="form-control" ng-model="ctrl.val.value" name="autocompleteField" required> < ...

Developing a custom styling class using JavaScript

Looking to create a custom style class within JavaScript tags. The class would look something like this: #file-ok { background-image: url(<?php echo json.get('filename'); ?>); } Essentially, the value returned from the PHP file (json ...

Eliminating the gaps between a vertical, asymmetrical, and intertwining stack of cards

I'm currently working on adjusting the layout of 12 vertical stacks of cards to remove excess empty space between them. The cards are already stacking nicely by rank, but there seems to be unwanted horizontal space between each pile, and I can't ...

A distinctive web page featuring an engaging image backdrop: captivating content effortlessly scrolling beneath

On my website, I have implemented a background image with a fixed transparent header. When scrolling down, I want the main content to be hidden beneath the header. To achieve this effect, I used the -webkit-mask-image property. However, this approach affec ...