How to create a form controller?

I’ve been working with Sage the last two weeks and I find it very powerful, but as I’m new with Laravel/Blade there are some things that I don’t understand how to do.

I want to create a custom form which will call a 3rd party API. I’ve created a controller called Forms.php, the HTML form and the AJAX call in jQuery. How can I call the controller function in the ‘url’ parameter in the jQuery Ajax call?

In a normal Wordpress I would do a .php to handle the data (validation and send the data) and send a response back to Ajax ‘success’. What’s the best way to do that in Sage?

Thanks in advance for your help!

Adding code for better understanding:


  let url = // What to use here?,
  data = $(this).closest('form').serialize();

    url: url,
    type: 'post',
    data: data,


namespace App\Controllers;
use Sober\Controller\Controller;

class Forms extends Controller
    public function processForm()
        return 'hello';

I would really appreciate your help.

You post to ajaxurl
Some reading:
You dont need the Controller for this at all.

Thank you for your answer Xilonz. You are right, I was trying to make it more difficult than it is.

Thanks so much :slight_smile:

This topic was automatically closed after 42 days. New replies are no longer allowed.