2

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

Thanks!

2

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.

| improve this answer | |
  • 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 Mar 21 '13 at 22:03
  • Ah, good catch Bryant. – Derek Hogue Mar 22 '13 at 13:12
  • Is there any documentation on how to set field errors as opposed to global errors? – developarvin Jul 8 '13 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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