21489 Posts in 5783 Topics by 2622 members
General Questions
SilverStripe Forums » General Questions » How to validate email in an extended Member class with modelAdmin
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1209 Views |
-
How to validate email in an extended Member class with modelAdmin

15 September 2010 at 4:59am Last edited: 15 September 2010 5:39am
Hello,
I have 2 classes : "ExtMember" and "ExtMemberAdmin"
+ ExtMember.php :
class ExtMember extends Member {
static $db = array(
'extName' => 'Varchar'
);}
+ ExtMemberAdmin.php :
class ExtMemberAdmin extends ModelAdmin {
static $url_segment = 'extMember';static $managed_models = array(
'ExtMember'
);
}When i add a new "ExtMember" member with an already registered email, this doesn't work : the "Add" button turns, turns and turns infinitely.
If i use Firebug to view the response, i have this :
ERROR [User Error]: Uncaught ValidationException:
IN POST /silverstripe-v2.4.1/admin/extMember/ExtMember/AddForm?action_doCreate=Ajout
Line 611 in /var/www/silverstripe-v2.4.1/sapphire/security/Member.phpSource
======
602: 'Member',
603: sprintf(
604: "\"%s\" = '%s' %s",
605: $identifierField,
606: Convert::raw2sql($this->$identifierField),
607: $idClause
608: )
609: );
610: if($existingRecord) {
* 611: throw new ValidationException(new ValidationResult(false, sprintf(
612: _t(
613: 'Member.ValidationIdentifierFailed',
614: 'Can\'t overwrite existing member #%d with identical identifier (%s = %s))',
615: PR_MEDIUM,
616: 'The values in brackets show a fieldname mapped to a value, usually denoting an existing email
address'
617: ),Trace
=====
Member->onBeforeWrite()
line 936 of DataObject.phpDataObject->write()
line 859 of ModelAdmin.phpModelAdmin_CollectionController->doCreate(Array,Form,SS_HTTPRequest)
line 300 of Form.phpForm->httpSubmission(SS_HTTPRequest)
line 137 of RequestHandler.phpRequestHandler->handleRequest(SS_HTTPRequest)
line 155 of RequestHandler.phpRequestHandler->handleRequest(SS_HTTPRequest)
line 149 of Controller.phpController->handleRequest(SS_HTTPRequest)
line 155 of RequestHandler.phpRequestHandler->handleRequest(SS_HTTPRequest)
line 149 of Controller.phpController->handleRequest(SS_HTTPRequest)
line 281 of Director.phpDirector::handleRequest(SS_HTTPRequest,Session)
line 124 of Director.phpDirector::direct(/admin/extMember/ExtMember/AddForm)
line 127 of main.phpI would like to know how to validate (only a unique email) "email" in a modelAdmin (like the email Member validation in Security Tab) ?
Thank you for your help,
-
Re: How to validate email in an extended Member class with modelAdmin

15 September 2010 at 11:16pm
To add validation to a DataObject that is used in Model Admin I do the following... however for "Member" this is a special case and I would have decorated or used a custom class when using this instead of just extending it... for more info that see here... http://doc.silverstripe.org/member?s[]=member#extending_member_or_dataobject
<?php
class ExampleDataObject extends DataObject
{
static $db = array(
'Name' => 'Text'
);
}class DataObject_Validator extends RequiredFields
{
function php($data)
{
$bRet = parent::php($data);if ($data['Name'] == 'Fred')
{
$obj->validationError(
'Name',
'Name must not be Fred',
"required"
);$bRet = false;
}return $bRet;
}
}
| 1209 Views | ||
|
Page:
1
|
Go to Top |


