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

  • SEARCH
  • Home
  • 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 8372075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:19:33+00:00 2026-06-09T14:19:33+00:00

Possible Duplicate: [PHP/JavaScript]: Call PHP file through JavaScript code with argument Ok so I

  • 0

Possible Duplicate:
[PHP/JavaScript]: Call PHP file through JavaScript code with argument

Ok so I use Javascript to validate my HTML forms input values, but I use PHP to write these values into a database.
Is it possible to send my form to the PHP file through Javascript?

This is how I did it without the Javascript, it’s supposed to send the form when you click the submit button to the PHP file.
This is my original form:

<form name="filler" method="post" action="display.php">
//form stuff
</form>

Here’s as far as I’ve gotten. Although I can’t see anything that is supposed to error nothing happens when it is time to validate my form with Javascript, it merely goes to the PHP immediately no matter what I type in. What is still wrong with it?

<!DOCTYPE HTML>

<html>
<head>
<script type="text/javascript">
    function required1(n,s,u,e,d,p,cp,g)  
    {  
        if (n.value.length > 0 && s.value.length > 0 && u.value.length > 0 && e.value.length > 0 && d.value.length > 0 && p.value.length > 0 && cp.value.length > 0 && g.value.length > 0)  
                {  
            return true;
        {
        else   
        {  
            alert('You have not filled in all the fields');  
            return false;   
        }  
    }
    function required2(e)
    {
        if(e.indexOf('.') != -1 && e.indexOf('@') != -1)
        {
            return true;
        }
        else
        {
            alert('Not a valid email address');
            return false;
        }   
    }
    function required3(d)
    {
        if(/^\d{2}\/\d{2}\/\d{4}$/.test(d))
        {
            return true;
        }
        else
        {
            alert('Date is not in the right format (DD/MM/YYY)');
            return false;
        }
    }  
</script>
</head>
<body>
<form name="filler" method="post" action="display.php" onsubmit="return required1(document.filler.name,document.filler.surname,document.filler.username,document.filler.email,document.filler.dob,document.filler.password,document.filler.confirm_password,document.filler.gender) && required2(document.filler.email) && required3(document.filler.dob) ">
    <input name="name" placeholder="Name..."/>
    <input name="surname" placeholder="Surname..."/>
    <input name="username" placeholder="Username..."/>
    <input name="email" placeholder="Email address..."/>
    <input name="dob" placeholder="YYYY/MM/DD"/>
    <input name="password" placeholder="Password" type="password"/>
    <input name="confirm_password" placeholder="Password" type="password"/>
    <input name="gender" placeholder="Gender..."/>
    <input type="submit" value="Submit"/>
</form>
</body>
</html>
  • 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-06-09T14:19:35+00:00Added an answer on June 9, 2026 at 2:19 pm

    There’s no reason to use AJAX for this. The most elegant and easiest way is to use the HTML form tag’s onsubmit event:

    <form name="filler" method="post" action="display.php" onsubmit="return validateForm()">
        //form stuff
    </form>
    

    This will call the JS function validateForm before submitting the form. If the function validateForm returns false, the form will not be submitted. Otherwise it will be submitted to your PHP file as usual.

    EDIT:

    Make sure you’re validating this input in your PHP as well, since Javascript can easily be disabled.

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

Sidebar

Related Questions

Possible Duplicate: Parse a JavaScript file through PHP I've been trying to pass a
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Call php function from javascript I understand that php is server side
Possible Duplicate: javascript substring How can I do substr (php) in JS? Example code
Possible Duplicate: How to call a JavaScript function from PHP? Can I add a
Possible Duplicate: Inserting PHP array into Javascript array I'm reading a file in server
Possible Duplicate: How to pass value from javascript to php file would something like
Possible Duplicate: Passing JavaScript Array To PHP Through JQuery $.ajax I'm trying to pass
Possible Duplicate: How can I use a JavaScript variable as a PHP variable? I
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,

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.