Custom server-side validation?
Posted: 08 February 2011 08:20 PM   [ Ignore ]
Wallflower
Avatar
Rank
Total Posts:  15
Joined  2010-10-22

Hi there, i’m trying to implement custom server-side validation for a safecracker form. I’ve got my custom extension working fine, listening out for the safecracker_submit_entry_start hook, but i can’t find out how to forward any custom errors on to SC, eventually returning my errors to the form page.

I’ve looked thru the forum, the docs and the SC sourcecode, but no joy. Is there a safecracker mechanism for custom server side validation?


Just to be specific: my custom validation extension receives an uploaded video from the form and sets up a remote video transcoding job, and so any errors from that are really important, considering the user has just uploaded a huge file.

Profile
 
 
Posted: 08 February 2011 10:02 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

What I’m suggesting is strictly experimental, but I think it will work. Within your extension, you can add an error to the safecracker object:

function safecracker_submit_entry_start($safecracker)
{
    
//on no, you've encountered a custom error!
    
$this->EE->safecracker->errors[] 'My custom error';
Profile
 
 
Posted: 08 February 2011 10:47 PM   [ Ignore ]   [ # 2 ]
Wallflower
Avatar
Rank
Total Posts:  15
Joined  2010-10-22

Works a treat! The errors come right back out into the form, along with any other errors picked up by SC itself. Wonderful work rob!

PS
I thought that in the extension context, errors were in held in $sc->field_errors, but it looks like $this->EE->safecracker->errors is the right place.

Profile