php - Validation Controller inside CMS in Silverstripe -


at moment have leftandmain section named 'applications' contains form password field: leftandmain content section

the code is:

class applications extends leftandmain {     static $url_segment = 'applications';     static $menu_title = 'applications';     static $url_rule = '$action/$id';      public function init(){         parent::init();     }      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){         $form->sessionmessage('correct password. redirect manage model', 'success');         return $this->redirectback();     } } 

when submiting form, action function should validate if it's equaly (in case, it's key decrypt data database) , redirect/show gridfield.

the second point modeladmin, can manage data (that comming database) through gridfield. managing data model

the code is:

class applications2 extends modeladmin {     static $url_segment = 'applications2';     static $menu_title = 'applications2';      private static $managed_models = array(         'secureforminput'     ); } 

and here question: possible ? suggestions/help becouse tried while , no result.

i'm finding hard figure out you're really trying do.

here few things can see might still though:

  1. you wouldn't extend leftandmain directly. 99% of time, developers building admin-screens or areas, in single or multiple model(s) (dataobject subclasses) managed.
  2. in applications class have no $allowed_actions static. need have @ least single value: 'applicationpassword' in order tell silverstripe legitimate actions controller can perform.
  3. again, depending on you're trying do, password protect cms admin area using silverstripe cms' standard permissions system (see "security" menu item). notice can authorise users or groups on some admin screens. if you're trying various custom controllers, should ensure controller declares canview() method. again see leftandmain.php examples.
  4. validation done @ model level. e.g. have dataobject subclass want manage within modeladmin. in case define method called validate() on dataobject subclass. when editing / creating new instances of model within modeladmin, cms knows run validate() method, if finds 1 on model.
  5. when "it isn't working" need know "in way?" e.g. see error message, not see should, if etc etc

if none of these points help, others you, if re-wrote question something like this:

"i trying password protect custom cms administration screen. have model mymodel following class definition (screenshot or code), , modeladmin (screenshot or code). code should show error message of password bad (a bad password 1 doesn't match 1 in database, or doesn't follow specific format etc etc) or success message of password matched db entry or did follow specific pattern or format."

good luck :-)


Comments