Jump to:

11001 Posts in 2733 Topics by 1823 members

All other Modules

SilverStripe Forums » All other Modules » UserForms - Get $data just before submit via extends

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 216 Views
  • omnicurse
    Avatar
    Community Member
    8 Posts

    UserForms - Get $data just before submit via extends Link to this post

    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.

  • omnicurse
    Avatar
    Community Member
    8 Posts

    Re: UserForms - Get $data just before submit via extends Link to this post

    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";
    }

    }

  • omnicurse
    Avatar
    Community Member
    8 Posts

    Re: UserForms - Get $data just before submit via extends Link to this post

    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.

    216 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.