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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:23:02+00:00 2026-05-23T08:23:02+00:00

I have an HTML multipart form, with name, email and file upload. I want

  • 0

I have an HTML multipart form, with name, email and file upload.

I want to register the user with Ajax first of all. If registration succeeds, I want to then proceed to submit the form. If it fails, I want to avoid submitting the form.

This is my code:

  --- HTML ---
   <form id="account-form" method="post" enctype="multipart/form-data" data-ajax="false" action="upload.php" >
   <input type="text" name="username" id="username" /> 
   <input type="email" name="email" id="email" /> 
   <input type="file" id="mediaupload" name="mediaupload" accept="image/*" />
   </form>
  --- JavaScript ---
  accountform.submit(function(event) {
    var registration_ok = true;
    // See if we can register the user
    // And if we can, submit the form. 
    $.ajax({
        type: "POST",
        url: "/usercreate.php",
        data: postdata,
        dataType: 'json',
        success: function(data) {
           // fine to submit the form. 
        },
        error: function (data){
            // If this fails, we don't want to submit the form!   
            registration_ok = false;
        }
    });
    return registration_ok;
  });

However, it’s always returning true – I guess this is because the main function returns before the Ajax error is called.

How can I prevent it from returning true, and submitting the form, when registration fails?

Thanks!

  • 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-23T08:23:03+00:00Added an answer on May 23, 2026 at 8:23 am

    You need to return false always, instead of registation_ok, and then in the success function, go:

    document.forms["account-form"].submit(); //edited
    

    i.e. never submit the form when you press the submit button, wait for the AJAX to return, and then only submit the form if the registration was successful.

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

Sidebar

Related Questions

I have the following html form... <html> <head><title>Upload Servlet</title></head> <body><h2>Upload Servlet</h2> <form name='uploadparams' enctype='multipart/form-data'
I have a working Ajax form, now I'm trying to add file upload to
I have an HTML form with an input field to upload a file. I
I have a HTML form ( upload.htm ) with a HTML file upload control
I have a HTMl form <form action= method=post enctype=multipart/form-data> <p> Banner Ad Name :<br
I have a basic upload form <html> <head> <title>Upload a File</title> </head> <body> <font
I have the following form: <html> <body> <form action=upload_file.php method=post enctype=multipart/form-data> <label for=file>Filename:</label> <input
So I have ajax file upload partial (using Jquery Form plugin), it's working perfectly,
I am trying to upload a file from a php form. I have verified
I have this html code <form method=post id=upload_video enctype=multipart/form-data action=/Home/Save> <div id=form_box> <input type=text

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.