Extend Form Controller?

Permalink
Hello again,

OK so i need help on how to properly extend the Form Block, if possible.

I'm creating a custom block that is essentially the Form Block with one main difference, it will need to submit its data to an external URL. (Concrete doesn't use webHooks so if someone could point in the right direction here that would be great. :))

I want the Results/Reports page show my submissions just like the regular Form, so the External Form Block wont work here.

We can skip the edit.php & add.php files since the form will be made form in the view.php ready to display.

My block is here to simply process form submissions from a specific form and send the data to another URL while still being available to view in Concrete.

My thinking was that i could extend for the Form Blocks controller in my Custom Blocks controller, thus having access to all of the parent classes methods and only needed to write a submission processing function.
Am i correct and if not what is the proper way to go about getting the results i want?

 
linuxoid replied on at Permalink Reply
linuxoid
Will AJAX do the trick? You can include any URL you wish in the call.
var post_data = {
    ...
}
$.ajax({
   dataType: 'json',
   type: 'post',
   data: post_data,
   url: YOUR_URL,
})
.done(function(response) {
   if (response['status'] === 'ok') {
      ...
   }
   else {
      ...
aaronStark replied on at Permalink Reply
Thanks, that actually helped once i found out how to hijack/overwrite a core block controller.
This article was actually what i needed:https://documentation.concrete5.org/developers/working-with-blocks/w...

For anyone coming across this in the future, here's the solution i came up with:
- create new directory in /application/blocks/form/
- create new controller.php inside the directory
- make new Controller extends the Core Form Block Controller
- overwrite the Core action_submit_form() in the new controller
- make sure our new action_submit_form() calls the parent method of the same name at the end( so it will still be saved)
- in the end my controller looked something like this:

<?php
namespace Application\Block\Form;
use Concrete\Block\Form\Controller as FormController;
class Controller extends FormController {
    // setup method to send data to another URL
    public function processForm($data = array()) {
        // verify form name; run code only if 'myForm' is submitted
        if ($this->surveyName === 'myForm') {
            // code from Linuxoid //
        } else {
            // form is not 'myForm', return
            return;
        }
    }
    // here we override the core submit method of the Form Controller, called on form submit


that was all it took, i can send form data my URL and Concrete will still submit and generate reports. (plus a custom template for form aesthetics)