Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Form not submitted by $(form).submit() subsequently

I'm doing a server-side form validation. On [submit] button clicked my code adds field _validate to the form and sends the form to the server in AJAX mode. On success form should be submitted, but it not happened.

$(document).ready(function(){

    $('form[action*="#validate"]').on('submit', function(e){
        var $form = $(this);
        var $submit = $form.find('input[type=submit]');
        var $validate = $form.find('input[name=_validate]');
        if ($validate.length>0 && $validate.val()=='success') // already validated
        {
            //e.returnValue = true; it's deprecated
            console.log('validated'); // #2
            return true; // supposed form submit
        }
        e.preventDefault();

        if ($validate.length==0)
            $form.append('<input type="hidden" name="_validate" value="asking" />');    
            $validate = $form.find('input[name=_validate]');
            var params = $form.serialize();
            $.ajax({
                url: $form.attr('action'),
                method: $form.attr('method').toLowerCase(),
                data: params
            })
                .then(function(response, statusText, xhrObj){
                    var json = JSON.parse(response);
                    if (json._status!='ok')
                    {
                        // writing messages
                    }
                    else
                    {
                        $validate.val('success');
                        $form.attr('action', $form.attr('action').replace('#validate', ''));
                        $form.submit(); // #1
                    }
                }); 

    });
    

});

form.submit() marked with #1 makes subsequest onsubmit call, the script prints validated (#2) but form woudn't submit - no queries in Net console, no error or warning messages.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!