1

I'm trying to extend the Craft UserController class, in order to add some extra validation to the actionSaveUser action, before the rest of the code in that function executes.

I've got no problem hitting my controller and even calling the parent::actionSaveUser which seems to be working, except for getting the validation error messages.

function actionSaveUser()
{
    parent::actionSaveUser();
    $this->renderTemplate('profile/index.html');
}

For brevity, I've not included any of the validation just yet. The template being rendered does display errors if routed to the Craft controller action, but not through mine.

The main reason for doing this is because uploading of a non-image for the profile image (e.g. uploading a php file) causes a php error, not a value in the returned errors array.

Any idea why the errors are disappearing when routing through my controller first?

Thank you in advance

Update

Looking through the UserController::actionSaveUser action, I can see

craft()->urlManager->setRouteVariables(array(
    'account' => $user
));

Looking through the urlManager documentation; I can see that _routeVariables is being updated but can't see a way of accessing this array to get the account value.

Am I looking in the wrong place?

Update The Second

Ok, even sending the form directly to users/saveUser isn't yielding any errors (account object isn't defined). But, if all fields are filled in, it correctly saves

Any suggestions?

0

While not a direct answer to your question, as of the next (post 2.4.2702) Craft release, Craft will now return a validation error on the UserModel if a non-image is uploaded for the user's profile photo.

|improve this answer|||||
0

After a lot of head-desking, and some input from a colleague, we realised the issue wasn't in the controller but in the form action declaration. I originally had

<form action="pluginname/controller/action"...

Changing it to this, seems to have resolved it.

<form>
    <input type="hidden" name="action" value="pluginname/controller/action">
|improve this answer|||||

Your Answer

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