Catalin Farcas
Catalin Farcas

Reputation: 655

Simple form for Model Admin in Silverstripe

By default, Model Admin is used to manage a model/s, and if the model is skipped, the result is an error.

/* private static $managed_models = array(
    'OneModel'
); */

I want to display a simple form (Textfield for a password and an action button) first, then if the password is correct, it should go the to a the gridfield.

I tried to change the getCMSfields inside the model, but the field is visible only if i click on one of the records from the gridfield:

public function getCMSfields(){
    $fields = FieldList::create(TabSet::create('Root', $login = Tab::create('Authorise', 
        TextField::create('Password')
    )));
    return $fields;
}

Edit:

This secondary password it's the key to decrypt the data for that DataObject, is not a regular login, so it's an additional security method to keep safe some sensitive data.

Upvotes: 0

Views: 575

Answers (1)

Catalin Farcas
Catalin Farcas

Reputation: 655

I figured out, for those in similar situation. Instead of using ModelAdmin, we can use LeftAndMain. so the code will be:

class Applications extends LeftAndMain {
    static $url_segment = 'applications';
    static $menu_title = 'Applications';
    static $url_rule = '$Action/$ID';

    public function init(){
        parent::init();
    }

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

    public function getEditForm($id = null, $fields = null) {
        $fields = new FieldList(
            TextField::create('Password', ' Password')
        );
        $actions = new FieldList(new FormAction('applicationPassword'));
        return new Form($this, "EditForm", $fields, $actions);
    }

    public function applicationPassword($data, Form $form){
        $pass = $data['Password'];
        $form->sessionMessage('Password submited for testing : '.$pass, 'success');
         return $this->redirect('login');
    }

     public function login(){
        return 'success';
    }
}

One more need would be, after validation, in the nest step to show the regular gridfield with the model records, but when i succed, i will return with an answer as well.

Upvotes: 1

Related Questions