Not outputting a URL on your form

I was reading the cakephp book, and I have a form that submits comments on an article.
my form on my view page as of now is defined because I am stuck on 3 things. One when I create a form, the request an ajax request, but my controller doesn’t seem to catch it in an if. Two, my jquery ajax URL undoubtedly appends the url defined in my ajax script to the current page and goes no where, and lastly I am confounded by the possibility of this option for a form

"Use ‘url’ => false if you don’t want to output a URL as the form action. "

.How do you submit an ajax form on cakephp?

Use in Form::create - “url” => “#”

in jquery

$("#yourFormId").on(‘submit’, function(e) {
e.preventDefault(); // stop propagation of default event - which is form submit

… your ajax call here
});

This did prevent the default redirect, and called my ajax which in turn called my other controller method.
Now my request data array is null?

    $('#yoursForm').on('submit', function(e) {
        $.ajax({
            method: 'POST',
            url: 'yourUrl',
            data : $('#yoursForm').serialize()
        }).done(function( response ) {
              console.log(response);
        });
        e.preventDefault();
    });
1 Like

Sir, I have to tell you , if you haven’t heard it today, but thank you you are awesome. After serializing my form data, I was able handle the request as anticipated.

1 Like