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 6327705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:19:41+00:00 2026-05-24T17:19:41+00:00

I’m trying to validate a form before posting the data. Basically the form asks

  • 0

I’m trying to validate a form before posting the data. Basically the form asks for a code. After the user clicks the submit button, the javascript below checks if the code only contains numbers and has a length of 6 digit. If the code is valid, then an ajax call is made calling the page verifybkcd.php, which runs a query and checks if the input code has associated with an account. Somehow the form is always submitted no matter what code I put.It seemed the ajax call has never been made because none of the alerts inside the call had been triggered. (I’m sure the path of the file verifybkcd.php is correct). Any ideas?

     $(document).ready(function(){

    $("#bksubmit").click(function(e){


       var bkcode = $("#bkcode").val();

       var bkcode_format =/^\d{6}$/;
       if(bkcode_format.test(bkcode)){

          $("#err-box").text("");
          $("#recovform").submit(function(e){

            alert("alert on submit");


            $.post("accounts/verifybkcd.php",{bcd:bkcode}, function(data){
                    alert("alert inside post");
                    if(data !=''){
                         alert("alert on code exists");
                        e.preventDefault();
                        $("#err-box").text("No account found with that book code. Please try again.");

                    }
                    else{

                        alert("alert on valid");
                        $("#err-box").text("");


                    }
            });

        });

       }
       else{

         $("#err-box").text("Please enter a valid book code above");
         e.preventDefault();
       }


    });

The following is taken from the php file which has the form

     <div id="container">
     <?php
    if($_SERVER['QUERY_STRING']==''){
     ?>
    <div class="title"><h1>Forgot your password?</h1></div>
    <div class="description"><p>To reset your password, enter the book code that you used when you registered your account.</p></div>

        <form id="recovform" name="recovform" method="post" action="recovery.php?verifyuser" >
            <div id="bkbox">
                <label for="bkcode">Book Code:</label>
                <input id="bkcode" name="bkcode" type="text" />
                <input id="bksubmit" name="submit" type="submit" value="Submit"/>
            </div>
           <div id="err-box"></div>
        </form>
     <?php
    } 
     else if($_SERVER['QUERY_STRING']=='verifyuser'){

     ?>
       <div class="title"><h1>verify user</h1></div>
       <div class="description"><p>emails below</p></div>
    <?php
     }
     else{
        echo "<META   HTTP-EQUIV=REFRESH   CONTENT='0;URL=../err/404.php'>";
     }
    ?>
</div>

BTW, I’m sure there’s nothing wrong with verifybkcd.php file. I’ve tested it with different codes. It will only return a string when there’re no accounts associated with the input code.


Problem solved. I replaced the name of the submit button with something else. Then it worked like magic. Also I’ve made a little change on the javascript as follows. It seems jquery won’t submit the form if you name the submit button “submit”. BTW I aslo changed the type of the submit button to “button” instead of “submit”

    $(document).ready(function(){

    $("#bksubmit").click(function(e){


       var bkcode = $("#bkcode").val();

       var bkcode_format =/^\d{6}$/;
       if(bkcode_format.test(bkcode)){

          $("#err-box").text("");

            $.post("accounts/verifybkcd.php",{bcd:bkcode}, function(data){
                    if(data !=''){   
                        $("#err-box").text("No account found with that book code. Please try again.");
                    }
                    else{

                        $("#err-box").text("");
                        $("#recovform").trigger("submit");

                    }
            });

       }
       else{

         $("#err-box").text("Please enter a valid book code above");
       }


    });



    });
  • 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-24T17:19:42+00:00Added an answer on May 24, 2026 at 5:19 pm

    First place if you dont want to submit the form then you should return false in the submit button click handler. Check if this below condition satisfied or not.

    $(document).ready(function(){
    

    //This is to prevent the form to be submitted
    $(“#recovform”).submit(function(e){
    e.preventDefault();
    });

    $("#bksubmit").click(function(e){
    
       var bkcode = $("#bkcode").val();
    
       var bkcode_format =/^\d{6}$/;
       if(bkcode_format.test(bkcode)){
    
          $("#err-box").text("");
          //$("#recovform").submit(function(e){
    
            //alert("alert on submit");
    
    
            $.post("accounts/verifybkcd.php",{bcd:bkcode}, function(data){
                    alert("alert inside post");
                    if(data !=''){
                        //alert("alert on code exists");
                        //e.preventDefault();
                        $("#err-box").text("No account found with that book code. Please try again.");
    
                    }
                    else{
    
                        //alert("alert on valid");
                        $("#err-box").text("");
    
                        $("#recovform").unbind('submit').submit(); 
                    }
            });
    
        //});
    
       }
       else{
    
         $("#err-box").text("Please enter a valid book code above");
         return false;
       }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.