I work in a functionality in which I must validate some fields before saving, if a condition is not met I must indicate abort the save process, according to the documentation of the onContentBeforeSave event I do this by returning false, this works fine, but I would like to add a personalized message. Right now when return false, the following message is displayed in the view
I understand after the colon a personalized message is expected. How I do this?
This is the plugin code I am trying
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
class plgContentMyPlugin extends JPlugin
{
public function onContentBeforeSave($context, &$article, $isNew, $data)
{
if ($context === 'com_content.article') {
$field1 = $data['com_fields']['field1'];
$field2 = $data['com_fields']['field2'];
if (!empty($field1) && empty($field2)) {
return false; // here, how can I attach a message?
}
$date = strtotime($field1);
$now = time();
if ($date > $now) {
return false; // here, how can I attach a message?
}
}
return true;
}
}
Thanks in advance
time()
andstrtotime()
. stackoverflow.com/q/12389391/2943403 and stackoverflow.com/q/13709834/2943403