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.

Form Questions /

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

Form creating, submit action problem


Go to End


1707 Views

Avatar
snaip

Community Member, 181 Posts

19 July 2012 at 8:43pm

Hi

I have problem with form. Submit action doesn't work:

FormIndex.php

class FormIndex extends Form {

    function __construct($controller, $name) {
        $fields = new FieldSet(
                        new TextField('FirstName', 'First Name'),
                        new TextField('Tel', 'Tel'),
                        new EmailField('Email', 'Email'),
                        new TextareaField('Frage', 'Frage')
        );

        $actions = new FieldSet(
                        new FormAction('doForm', 'Submit')
        );

        parent::__construct($controller, $name, $fields, $actions);
    }

    function doForm($data, $form) {
        print_r($data);
        exit;
        // do procedures after form is submitted here 
    }

}

Start.php

class Start_Controller extends StaticPage_Controller {

    public static $allowed_actions = array(
        'doForm'
    );

    public function formularz(){
        $form = new FormIndex($this,'FormIndex');
        $form->setFormAction($this->link('doForm'));
        return $form;
    }

}

nothing happens, after submit form site is redirecting to /home/doForm but this action doesn't work

    function doForm($data, $form) {
        print_r($data);
        exit;
        // do procedures after form is submitted here 
    }