# How to create a form controller?

**URL:** https://discourse.roots.io/t/how-to-create-a-form-controller/15396
**Category:** sage
**Tags:** blade
**Created:** 2019-04-26T09:27:47Z
**Posts:** 5

## Post 1 by @Alfalfa — 2019-04-26T09:27:47Z

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!

**EDIT**  
Adding code for better understanding:

**Common.js**

```
$('form').submit(function(e){
  e.preventDefault();
  let url = // What to use here?,
  data = $(this).closest('form').serialize();

  $.ajax({
    url: url,
    type: 'post',
    data: data,
    success:function(response){
      alert(response);
    },
   });
  });
```

**Form.php**

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

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

---

## Post 2 by @Alfalfa — 2019-04-29T07:26:13Z

I would really appreciate your help.

---

## Post 3 by @Xilonz — 2019-04-30T19:56:48Z

You post to ajaxurl  
Some reading: [https://codex.wordpress.org/AJAX\_in\_Plugins](https://codex.wordpress.org/AJAX_in_Plugins)  
You dont need the Controller for this at all.

---

## Post 4 by @Alfalfa — 2019-05-01T08:50:01Z

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:

---

## Post 5 by @system — 2019-06-07T09:27:51Z

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