7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Displaying user_error messages in DataObjectManager
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1331 Views |
-
Displaying user_error messages in DataObjectManager

2 March 2010 at 2:55am Last edited: 2 March 2010 3:01am
Hi,
I'm using a ManyManyDataObjectManager asociated to a DataObject, and I'm checking some fields within an OnBeforeWrite method.
The checking process works fine, but the error messages look pretty awful (it displays source code and trace data). This is the code I'm using in the OnBeforeWrite() method:
...
function onBeforeWrite() {
parent::onBeforeWrite();
// check for unique artist name (LastName + FirstName)
$where = "FirstName = '$this->FirstName' AND LastName = '$this->LastName'";
if ($this->ID) { // not first write action
$where .= " AND ID != '$this->ID'";
}$artists = DataObject::get("Artist", $where);
if($artists) {
user_error('The artist already exists', E_USER_ERROR);
exit();
}
}
...Is there any special way for displaying/beautifying error messages related to a DataObjectManager?
Thanks in advance.
-
Re: Displaying user_error messages in DataObjectManager

2 March 2010 at 3:28am
No.. you can't do that much of anywhere in Silverstripe without building a custom form. But I really like the idea. You might be able to do it with Form validation, though. I think onBeforeWrite() is definitely the wrong place for that..
-
Re: Displaying user_error messages in DataObjectManager

3 March 2010 at 1:31am
Thanks for your fast reply.
I'll follow your hints.
-
Re: Displaying user_error messages in DataObjectManager

4 March 2010 at 10:28am
A few thoughts.. if you're open to merging the FirstName and LastName field, you could use a UniqueTextField. That will inherently validate what you're trying to emulate in your onBeforeWrite() function.
I think what really needs to happen is that the DOM should offer a callback function on the submit, so that you could have a custom controller inspect and approve the post data before saving the record..
Something like:
doSave($data, $form)
{
if($this->callback && $this->controller->hasMethod($this->callback)) {
$method = $this->callback;
$this->controller->$method($data, $form)
}
// continue with form processing
}and then in your controller you could have something like
public function myDOMCallback(&$data, &$form)
{
if($data['Foo'] != "Bar")
$form->setErrorMessage("Fail!","Foo");
}Something to think about.
-
Re: Displaying user_error messages in DataObjectManager

6 August 2010 at 5:54am Last edited: 6 August 2010 5:57am
I ran into this issue as well. With the ComplexTableField you can set a custom validator as long as you have a getValidator method in your DataObject (I don't know why it isn't called getCMSValidator like in the rest of the CMS). Unfortunately, the DataObjectManager_Popup class unsets any custom validator you add.
Is there a reason $this->unsetValidator() is called in the constructor of DataObjectManager_Popup?
| 1331 Views | ||
|
Page:
1
|
Go to Top |


