Jump to:

23372 Posts in 18174 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Policy agreement

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 801 Views
  • cumquat
    Avatar
    Community Member
    191 Posts

    Policy agreement Link to this post

    Hi there,

    I have a requirement for members of a site to annually agree a confidentiality policy as well as a few others. The thought is for this process to be come electronic and part of the website. Currently team members login to a team site where information is stored what i want to do is to come up with a way of them agreeing a policy by ticking a box and then re entering their password this will then log the tick box and the date it was ticked. Has anyone done something similar and how do you get a logged in member to have to log in again?

    Any help or pointers please.

    Mick

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: Policy agreement Link to this post

    I would suggest you have a normal form, with a validator that using the checkpassword (http://api.silverstripe.org/2.4/sapphire/security/Member.html#methodcheckPassword) to validate the it is the memeber and then in the form action can updat the relelvant boolean field on the member/decorated member object

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Policy agreement Link to this post

    Nice that seems like a nice way, will give that a go.

    Cheers

    Mick

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Policy agreement Link to this post

    Ok its late and the brain isnt working very well, i have my form but i have no idea how to call the checkpassword validator or function. below is my form code, anyone able to give me some direction please?

    Mick.

    function PolicyForm() {
       
       Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
       Requirements::javascript(THIRDPARTY_DIR .'/jquery-ui/jquery.ui.core.js');
       Requirements::javascript(THIRDPARTY_DIR .'/jquery-ui/jquery.ui.datepicker.js');
       
       
          $fields = new FieldSet(
             
             new DatePickerField('DateTaken', 'Date Agreed'),
             new TextField('password'),
             new HiddenField('SkillID','', 24),
             new HiddenField('MemberID','', 1)
             );
          
          $validator = new RequiredFields(
    'password'
    );
          
          $actions = new FieldSet(
             new FormAction('doPolicyinfo', 'Submit')
          );
          
          return new Form($this, 'PolicyForm', $fields, $actions, $validator);
          
          }
             
       function doPolicyinfo($data, $form) {
          $Course = new Course();
          $form->saveInto($Course);
          $Course->write();
          
          
          Director::redirectBack();
          }

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: Policy agreement Link to this post

    change

    $validator = new RequiredFields( 'password' );

    for

    $validator = new PolicyForm_Validator( 'password');

    and add...

    class PolicyForm_Validator extends RequiredFields {
       function php($data) {
          $bRet = parent::php($data);

          $doMember = Member::currentUser();

          if (!$doMember->checkPassword($data['password'])) {      
             $this->validationError('password','wrong password',"required");
             $bRet = false;
          }
          
          return $bRet;
       }
    }

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Policy agreement Link to this post

    Hi there,

    Many thanks for the code. I have had a play but im guessing im missing something fundamental, although the form saves the data it does it even if the password entered is incorrect. I have pasted my full code below.

    <?php
    class Policy extends Page {

       static $db = array(
              
       );
       static $has_many = array(
       
       );

    function getCMSFields() {
          $fields = parent::getCMSFields();
          return $fields;
       }
    }
    class Policy_Controller extends Page_Controller {

       public function init() {
          parent::init();
             Requirements::css('sar/css/sar.css');
       }

       
       function PolicyForm() {
       
       Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
       Requirements::javascript(THIRDPARTY_DIR .'/jquery-ui/jquery.ui.core.js');
       Requirements::javascript(THIRDPARTY_DIR .'/jquery-ui/jquery.ui.datepicker.js');
       
       
          $fields = new FieldSet(
             
             new DatePickerField('DateTaken', 'Date Agreed'),
             new TextField('password'),
             new HiddenField('SkillID','', 24),
             new HiddenField('MemberID','', 1)
             );
          
          $validator = new PolicyForm_Validator(
    'password'
    );
          
          $actions = new FieldSet(
             new FormAction('doPolicyinfo', 'Submit')
          );
          
          return new Form($this, 'PolicyForm', $fields, $actions, $validator);
          
          }
             
       function doPolicyinfo($data, $form) {
          $Course = new Course();
          $form->saveInto($Course);
          $Course->write();
          Director::redirectBack();
          }

    }

    class PolicyForm_Validator extends RequiredFields {
    function php($data) {
    $bRet = parent::php($data);

    $doMember = Member::currentUser();

    if (!$doMember->checkPassword($data['password'])) {
    $this->validationError('password','wrong password',"required");
    $bRet = false;
    }

    return $bRet;
    }
    }

    ?>

    The template page.

    iv class="twoCol">

    <% include Sidebar %>

    <div id="content" class="typography">
          
             $PolicyForm
          
          
          
          
       </div> <!-- /Content -->

    <div class="clear">&nbsp;</div>

    </div><!-- /Two Column Layout -->

    regards Mick

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: Policy agreement Link to this post

    can you use log statements / debugger to check if the validators php function is being called?

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Policy agreement Link to this post

    Ok the function is being called, i've placed

    die($bRet);


    both before the

    if (!$doMember->checkPassword($data['password'])) {
    $this->validationError('password','wrong password',"required");
    $bRet = false;
    }

    and after and it always responds with a 1 whether the password is correct or false.

    801 Views
Page: 1 2
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.