83 Posts
squareweb
6 years ago
Topic

Hi, I'd like to stop the save(storing)-process when a condition is met in before-store-field (I check if content-item exist in DB).

A warning should be displayed (like "item already exist") and user should stay on content-form.

Any ideas?

thanks in advance

Mark

Get a Book for SEBLOD
83 Posts
squareweb
6 years ago
3
Level 1

It is possible to use Location('url'); exit;

Of course execution will stop and nothing gets saved...but then I loose the error-message, this wil not be displayed... 

There must be a more graceful (seblod) way to prevent saving a content-item.

Anybody?

This is the case:

// in before-store field:

check-existence();

if-exist{

     stop here, show warning/error (how to do this)

} else {

   continu saving

}

4229 Posts
Kadministrator
6 years ago
2
Level 2

You could use joomla redirect that displays a message, same way joomla does if there is no access:

JFactory::getApplication()->redirect('someurl', 'some message', 'message type e.g. error');

83 Posts
squareweb
6 years ago
1
Level 3

Thanks Klas, this works indeed.

I'll use this solution until I have my copy of ajax-validation up and running.

I'll post about that in the plugin-forum.

Thank again Klas for helping me (and the community).

regards

83 Posts
squareweb
6 years ago
0
Level 4

To be complete, this is my current code:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)');
$query->from($db->quoteName('#__cck_mytablename'));
$query->where($db->quoteName('dnt_trid') ." = " . $fields['dnt_trid']->value . " AND " . $db->quoteName('dnt_user') ." = " . $fields['dnt_user']->value); 

// Reset the query using our newly populated query object.
$db->setQuery($query);
$count = $db->loadResult(); 

// warning if record(s) found
if($count > 0){
  // throw error
 $error = "Deze deelnemer is reeds aan dit traject gekoppeld!";
 JFactory::getApplication()->redirect($fields['sysdisplayfield']->value, $error, 'warning');
}

Get a Book for SEBLOD