Skip to content
Advertisement

Can’t prevent client side submission php

I’ve created a register page using php, and the the form successfully sends data to the database.

I’m trying to prevent client side submission, but I can’t get the form to stop submitting, even with nothing in the input fields.

It also submits every time and I refresh the page, and I’m not sure why.

I tried to temporarily removing the php, but I’m still having the same issue.

Before I do any further form validation, I need to the form to stop submitting.

Register page with html and php

JavaScript

App.js with form validation

JavaScript

Advertisement

Answer

You are registering event listener after the form has been submitted through onsubmit="validateRegistrationForm()". You should add event listener outside the validateRegistrationForm function. Like this:

JavaScript

and remove onsubmit from button:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement