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

SafeCracker hooks

Development and Programming

cfenwick's avatar
cfenwick
53 posts
14 years ago
cfenwick's avatar cfenwick

I’m trying to make an extension that will do something after the user has submitted a safecracker form. I’ve created a hook on the safecracker_submit_entry_end and it triggers when the form is submitted, whether it has passed inline validation or not. How do I find out if the form has passed validation in my code? The documentation at http://ellislab.com/expressionengine/user-guide/modules/safecracker/development.html doesn’t mention this at all.

Here is the safecracker code:

{exp:safecracker channel="profile" return="/thank-you" id="publishform" include_jquery="no" author_only="no" error_handling="inline" .... }
       
Dan Decker's avatar
Dan Decker
7,338 posts
14 years ago
Dan Decker's avatar Dan Decker

Hi cfenwick,

As I understand, you are developing an extension that listens for the safecracker_submit_entry_end hook, is that correct?

I would expect that the form would have passed validation if the hook is called, since validation happen inline with the SafeCracker form.

However, we don’t offer support for add-on development, we just aren’t set up to do so. To get you to the right audience, I’m going to move this into Development and Programming.

Cheers!

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
14 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

The hook on safecracker_submit_entry_end will trigger if entries data has been saved passing the validation (inline).

       
cfenwick's avatar
cfenwick
53 posts
14 years ago
cfenwick's avatar cfenwick

That’s the problem I’m having, safecracker_submit_entry_end is triggering whether it has passed validation or not.

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
14 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

are you setting the validation rule into safecracker tag

{exp:safecracker channel="profile" return="/thank-you" id="publishform" include_jquery="no" author_only="no" error_handling="inline" .... }

like

rules:my_field_name="required|min_length[5]"

try it, it may validation the inputs before triggering safecracker_submit_entry_end.

       
cfenwick's avatar
cfenwick
53 posts
14 years ago
cfenwick's avatar cfenwick

Yes, I’ve got them. here’s the full tag:

{exp:safecracker channel="profile" return="/thank-you" 
id="publishform" include_jquery="no" author_only="no"
error_handling="inline"
rules:title="required|min_length[5]"
rules:gp_practice="required"
rules:gp_email="valid_email|required"
rules:gp_address="required"
rules:gp_city="required"
rules:gp_postcode="required"
rules:gp_latitude="required"
rules:gp_longitude="required"
}
       
Rob Sanchez's avatar
Rob Sanchez
335 posts
14 years ago
Rob Sanchez's avatar Rob Sanchez

You can see if validation passed by checking SC for any errors:

$validation_passed = empty($this->EE->safecracker->errors) && empty($this->EE->safecracker->field_errors);

if ( ! $validation_passed)
{
    exit("YOU FAIL!");
}
       
cfenwick's avatar
cfenwick
53 posts
14 years ago
cfenwick's avatar cfenwick

It worked! Thanks Rob.

       

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.