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