How to Handle “Save failed with the following error:” When There Is No Error!

Note: This post is targeted at Joomla developers.

We were seeing the following error while trying to save the data in a Joomla form that we have created in the admin:

Save failed with the following error: (with the colon at the end)

The above tells us that there is a problem with saving the data (and indeed the data was not saved), but it didn’t tell us why. We checked the model of the form that we were trying to save, and everything seemed OK. In fact, the model was pretty standard, with just one difference, we were using the save method.

The save method, for those of you who don’t know, will override the standard save method of the component. This will allow the developer to write his own custom save, which is particularly helpful when the form saves its data to multiple tables.

Now, as soon as we removed the save method, everything worked as it should, so the problem really lied in that method. We reduced the method to just a simple update to one table (and we made sure that the query works), but to no avail, we were still seeing the same error!

We then started searching Joomla’s core files to see where this error is thrown. We discovered that the error (which is stored in the constant JLIB_APPLICATION_ERROR_SAVE_FAILED) was thrown by the file controllerform.php which is located under the libraries/joomla/application/component directory. The error was thrown at line 700 of that file in the function save. We checked the condition before that line, and it was:

if (!$model->save($validData))

Aha! So the save method in the JControllerForm class expects that the save method of the model to return true! So, to solve the problem, all that we needed to do is to add the following code at the end of the save function in our model:

return true;

Yes – it was that simple!

So, if you’re developing a Joomla component from scratch or if you are working on a component developed by someone else and you see this error, then try returning true in the save method of the model in question – it should work! If it still doesn’t and/or if you need help developing your component, then please contact us! Many Joomla development firms outsource work to us – possibly because we know a lot about Joomla, our rates are affordable, and we are always reliable.

3 Responses to “How to Handle “Save failed with the following error:” When There Is No Error!”
  1. Comment by Dave — July 7, 2014 @ 2:18 am

    I had the same problem, except it did save the data to the database. I had to change….

    parent::store($updateNulls);

    to

    return parent::store($updateNulls);

    when overriding JTable::store()

  2. Comment by Bien Thuy — October 13, 2015 @ 8:46 pm

    I have same problem but with Joomla Core Banner Component. When I press “New Category” and input all the data, and then press save, it shows the following error: “Error: Save failed with the following error:”. Just this error, with no additional details.

    Did you have this problem and could you tell me how to fix it?

  3. Comment by Fadi — October 21, 2015 @ 5:35 am

    Hi Bien,

    Have you tried applying the solution in this post: http://www.itoctopus.com/save-failed-with-the-following-error-invalid-parent-id-error-on-joomla to your case? Just try rebuilding the banner categories and then open the parent category (as well as the grand parent categories) and save them. I suspect your issue is caused by a corruption in the assets table.

Leave a comment