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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Policy agreement


Go to End


10 Posts   1623 Views

Avatar
cumquat

Community Member, 201 Posts

1 May 2012 at 10:16pm

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

Avatar
swaiba

Forum Moderator, 1899 Posts

1 May 2012 at 11:51pm

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

Avatar
cumquat

Community Member, 201 Posts

2 May 2012 at 1:07am

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

Cheers

Mick

Avatar
cumquat

Community Member, 201 Posts

2 May 2012 at 8:36am

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();
		}

Avatar
swaiba

Forum Moderator, 1899 Posts

2 May 2012 at 7:43pm

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

Avatar
cumquat

Community Member, 201 Posts

3 May 2012 at 12:06am

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

Avatar
swaiba

Forum Moderator, 1899 Posts

3 May 2012 at 12:37am

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

Avatar
cumquat

Community Member, 201 Posts

3 May 2012 at 1:28am

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.

Go to Top