I'm doing some post-processing after a Safecracker form has been submitted. During my post-processing if I want to encounter an error, I'd like to set one and have it show up as an error when the page reloads. I would assume you can do this somehow using the $safecracker object you have use of inside the hook, I'm just not sure how.

Any help or insight would be appreciated


1 Answer 1


Sure. First, you probably want to use safecracker_submit_entry_start. If you use safecracker_submit_entry_end, the entry will already be in the database, which presumably you want to avoid if your custom error conditions are met.

Setup your extension to use the safecracker_submit_entry_start hook (you can use pkg.io for a quick start), and have it call a method of the same name in your extension.

Then, pass the Safecracker object by reference so you can modify it in the parent context rather than locally.

function safecracker_submit_entry_start(&$safecracker)
    // do some stuff
    $safecracker['errors'][] = 'You didn't pass my special tests.';

That should be it.

  • 1
    Oops looks like I confirmed a little too soon, the actual code should be $safecracker->errors[] = "You didn't pass my special tests.";
    – Bryant
    Commented Mar 21, 2013 at 22:03
  • Ah, good catch Bryant. Commented Mar 22, 2013 at 13:12
  • Is there any documentation on how to set field errors as opposed to global errors? Commented Jul 8, 2013 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.