Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:55:35+00:00 2026-05-23T16:55:35+00:00

Okay, so I want to validate a form with Javascript before I validate it

  • 0

Okay, so I want to validate a form with Javascript before I validate it with PHP. If the Javascript function, let’s call it validate(), detects an error, I want to prevent the PHP from being executed.

There is only one way that I know of which would enable me to do so:
Using a link instead of a submit button, like this:

<a href="javascript:validate()">Login </a>

This could be the function validate():

function validate() {
//Do all the validation
document.form_name.submit(); }

However, there is one problem with this: My PHP scripts cannot know when exactly the form is submitted. Without Javascript, I would do this:

if ($_POST[button_name]) 

Now, though, there is no submit button, so the expression becomes obsolete.

So, in summary my question is:

How can I validate a form with Javascript and prevent the PHP validation from being executed if there is an error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:55:36+00:00Added an answer on May 23, 2026 at 4:55 pm

    You should have a submit button, so that even the users without js enabled can still send the form, and it will be validated by php.

    With js you can prevent the form submission, then check for validation and submit after you have validate it correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay all, I have a form that I want users to fill out. When
Okay, I want to have an app that takes phone numbers from an online
Okay. I want to transfer a number of templates from an Expression Blend Silverlight
Okay, I am a noob and want to get a array from my server
Okay, I want some jQuery/JavaScript to show an yellow background-color when its checked. I
okay so I want to make a public function that will return YES if
Pointless Dribble Okay This is another weird one from me, i want to thank
Okay so I want to make an application that launches other applications. However, the
Okay, so basically I want to be able to retrieve keyboard text. Like entering
Okay, so I have a UITableView that I want to apply themes to. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.