Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

UserForms - Get $data just before submit via extends


Go to End


3 Posts   1135 Views

Avatar
omnicurse

Community Member, 8 Posts

25 April 2014 at 4:01pm

Heya,

I'm working on a connector for the UserForms to send data to a third party service on submit. I'm just not sure how to get override/extend functions in PHP to make this possible.

Currently have a simple class

class ServiceConnector extends Extension
{

    public function onAfterInit()
    {
        echo "<h1>TEST!</h1>";
    }

}

and in a config.yml I've got

UserDefinedForm_Controller:
  extensions:
    - ServiceConnector 

This works in the sense that TEST! is showing up each time a page where a userform is displayed (Testing I've got the extension at least partially correct), but how do I go about getting the actual data json array?

I thought I would have been able to 'extend' the process method from the userform controller but if I try and do something like

class ServiceConnector extends Extension
{

    public function process($data, $form)
    {
        echo $this->owner->data
    }

}

I get nothing, so assuming its not calling my version of the method? Same can be said for any method I try and extend/modify.

Avatar
omnicurse

Community Member, 8 Posts

25 April 2014 at 5:35pm

After a bit of googling, seems an easier way is to subclass the Userform_Controller and override the process method.

If thats the case, why is this function ignored?

class TestConnector_Controller extends UserDefinedForm_Controller
{

    private static $allowed_actions = array(
        'process'
    );

    public function process($data, $form)
    {
        echo "TEST";
    }

}

Avatar
omnicurse

Community Member, 8 Posts

25 April 2014 at 5:55pm

Seems this is now more a blog than a request for assistants.

For anyone else; The reason the second solution is being ignored is I forgot to inject the subclass. In the config.yml simply adding

Injector:
  UserDefinedForm:
    class: TestConnector

Solved the issue. Pressing forwards.