21288 Posts in 5733 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 504 Views |
-
Policy agreement

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
-
Re: Policy agreement

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
-
Re: Policy agreement

2 May 2012 at 1:07am
Nice that seems like a nice way, will give that a go.
Cheers
Mick
-
Re: Policy agreement

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();
} -
Re: Policy agreement

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;
}
} -
Re: Policy agreement

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"> </div>
</div><!-- /Two Column Layout -->
regards Mick
-
Re: Policy agreement

3 May 2012 at 12:37am
can you use log statements / debugger to check if the validators php function is being called?
-
Re: Policy agreement

3 May 2012 at 1:28am
Ok the function is being called, i've placed
die($bRet);
both before theand after and it always responds with a 1 whether the password is correct or false.if (!$doMember->checkPassword($data['password'])) {
$this->validationError('password','wrong password',"required");
$bRet = false;
}
| 504 Views | ||
| Go to Top | Next > |


