We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Adding custom error message to Safecracker using hook

Development and Programming

bryantAXS's avatar
bryantAXS
50 posts
13 years ago
bryantAXS's avatar bryantAXS

Hey all,

I’m doing some validation of data inside the Safecracker “entry_submission_end” hook and I’m wondering if there is a way to add a custom global error to Safecracker, after the page reloads?

I’m sure there is a way of doing it, I just don’t want to spend a few hours digging through the safecracker_lib file.

Thanks!

Bryant

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
13 years ago
Rob Sanchez's avatar Rob Sanchez

You should be able to do something like this:

if (isset($this->EE->safecracker))
{
    $this->EE->safecracker->errors[] = 'Some global error';

    //or

    $this->EE->safecracker->field_errors['title'] = 'Title must start with Z!'
}
       
bryantAXS's avatar
bryantAXS
50 posts
13 years ago
bryantAXS's avatar bryantAXS

Great, thanks Rob!

       
bryantAXS's avatar
bryantAXS
50 posts
13 years ago
bryantAXS's avatar bryantAXS

Rob, is there any tag or way to know if Safecracker submitted successfully? I can’t use {error_count} == 0 because when a page initially loads, it will always come back as zero… any recommendations?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.