I am running Freeform 1.9.0 and I have a small plugin that is supposed to save user submission id's to a custom user field. The plugin returns error when it runs after a new user submits a form though.

Here is the error

Call to a member function getContent() on null

Here is the code

        function (Event $event) {
            $submission = $event->params["model"];
            $isNew    = $event->params["isNew"];

            $submissionId = $submission->id;

            $user = craft()->userSession->getUser();

            $user->getContent()->submissionID = $submission->getId();
            $success = craft()->users->saveUser($user);

            if (!craft()->users->saveUser($user))
                $errors = $user->getErrors();

Please read the article handling errors gracefully in Craft it will explain to code defensively and what to do in those scenarios. Your $user variable is null and you can't execute functions on null variables

| improve this answer | |

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.