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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:44:56+00:00 2026-05-26T08:44:56+00:00

I’m validating and posting form data via ajax with code below. The problem is,

  • 0

I’m validating and posting form data via ajax with code below.

The problem is, it doesn’t break posting if during validation occured an error. Here is my code

var autoSaveInterval = null;
var counter = 0;

function call() {
    postViaAjax(true)
}

function postViaAjax(autosaveMode) {
    var name = $("#name").val();
    var title = $("#title").val();
    var menu = $("#menu").val();
    var parentcheck = $(".parentcheck:checked").val();
    var id = $("#id").val();
    var author_id = $("#author_id").val();
    if (parentcheck == 0) {
        var parent = parentcheck;
    } else {
        var parent = $("#parent").val();
    }
    var content = CKEDITOR.instances['content'].getData();
    content = encodeURIComponent(content);
    var dataString = 'name=' + name + '&title=' + title + '&menu=' + menu + '&parentcheck=' + parentcheck + '&id=' + id + '&parent=' + parent + '&content=' + content + '&author_id=' + author_id;
    $.ajax({
        type: "POST",
        url: "processor/dbadd.php",
        data: dataString,
        dataType: "json",
        success: function (result, status, xResponse) {
            var message = result.msg;
            var err = result.err;
            var now = new Date();
            if (message != null) {
                if (autosaveMode) {
                    $('#submit_btn').attr({
                        'value': 'Yadda saxlanıldı ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
                    });
                } else {
                    $.notifyBar({
                        cls: "success",
                        html: message + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
                    });
                }
            }
            if (err != null) {
                $.notifyBar({
                    cls: "error",
                    html: err
                });
            }
        }
    });
};



function validate() {
    var name = $("#name").val();
    if (name == "") {
        $.notifyBar({
            cls: "error",
            html: "Səhifənin qısa adını daxil edin"
        });
        return false;
    }
    var title = $("#title").val();
    if (title == "") {
        $.notifyBar({
            cls: "error",
            html: "Səhifənin geniş adını daxil edin"
        });
        return false;
    }
    var menu = $("#menu").val();
    if (menu == "") {
        $.notifyBar({
            cls: "error",
            html: "Səhifə harada yerləşəcək? Mütləq birini seçin"
        });
        return false;
    }

    var parentcheck = $(".parentcheck:checked").val();
    var parent = $("#parent").val();
    if (!$(".parentcheck").is(":checked")) {
        $.notifyBar({
            cls: "error",
            html: "Ayrıca yoxsa hansısa başlıq altında? Mütləq birini seçin"
        });

        return false;
    } else if (parentcheck == '1') {
        if (parent == '0') {
            $.notifyBar({
                cls: "error",
                html: " Parent səhifəni seçin"
            });
            return false;
        }
    }

    return true;
}

$(document).ready(function () {

    $('.autosave').hide();
    $("#add_form").submit(function (e) {
        if (counter === 0) {
            if (validate()) {
                $('.autosave').show();
                counter++;
            }
        }
        postViaAjax(false)
        e.preventDefault();
    });


    $('#autosave').click(function () {
        if ($(this).is(':checked')) {
            if (autoSaveInterval) {
                clearInterval(autoSaveInterval);
            }
            autoSaveInterval = window.setInterval(call, 5000);

        } else {
            $('#submit_btn').attr({
                'value': 'Yadda saxla'
            });
            if (autoSaveInterval) {
                clearInterval(autoSaveInterval);
                autoSaveInterval = null;
            }
        }
    });

});

How to fix that problem? I want to show only message and break posting

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

    Change your “submit” function :

    $("#add_form").submit(function (e) {
        if (counter === 0) {
            if (validate()) {
                $('.autosave').show();
                counter++;
            }
            else // Add this:
                 return false;
        }
        postViaAjax(false)
        e.preventDefault();
    
    
    });
    

    This should help you

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.