C57 Ajax Route

Permalink 1 user found helpful
Hi guys,

I'm trying to send a form with AJAX. Normally I'd use a tool file, but I've heard they are kind of deprecated now.

What would be the recommended way to send a form with AJAX?

class Controller extends BlockController {
  public function on_start()
      {
         Route::register('/contact_form/process_form', '\Packages\ContactForm\Block\ContactForm\Ajax\Ajax::processForm');
      }
}


This doesn't seem to work if I try to access /index.php/contact_form/process_form. I'm getting a 404. If I add an echo of or exit before the register method, I first get the 404. This makes me think that the route is added too late.

What am I doing wrong?

Adri

A3020
 
Shotster replied on at Permalink Reply
Shotster
If the block is part of a package, try registering the route from the package controller's on_start() method.
Shotster replied on at Permalink Reply
Shotster
A3020 replied on at Permalink Reply
A3020
Ah, I put the on_start in the block controller. Ok, one step further. I now get a Class doesn't exist error. Any ideas?

// packages/d3_contact_form/controller.php
Route::register('/d3_contact_form/process_form', '\Concrete\Package\D3ContactForm\Block\D3ContactForm\Ajax\Ajax::processForm');
// packages/d3_contact_form/blocks/d3_contact_form/ajax/ajax.php
namespace Concrete\Package\D3ContactForm\Block\D3ContactForm\Ajax;
class Ajax extends Controller
public function processForm()
// url
index.php/d3_contact_form/process_form