PencilBlue adding new field to the sign up form

54 Views Asked by At

I'm trying to add a user role field into the sign up form in my PencilBlue site. Created my own plugin, copied \controllers\actions\user\sign_up.js and set the getRoutes.

Now I'm getting this error: Cannot set property 'position' of null. I did all that is needed for creating a new plugin. It all works fine when the core sign-up.js file is edited with

var user_type = post.admin['id'];
        if(user_type == 0){
            post.admin      = pb.SecurityService.ACCESS_USER;
        } else {
            post.admin      = pb.SecurityService.ACCESS_WRITER;
        }

I'm getting an error when used it in my plugin. I set the getRoutes like this

SignUp.getRoutes = function(cb) {
        var routes = [
            {
                method: 'post',
                path: '/actions/user/sign_up',
                auth_required: false,
                content_type: 'application/json'
            }
        ];
        cb(null, routes);
    };

The template HTML file is passing the post values just fine. The structure of my plugin controller directory is flat, so no subdirectories that follows the core set up, exactly how advised by PB team.

1

There are 1 best solutions below

0
On BEST ANSWER

following this thread, please add

request_body: ['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data']

inside the getRoutes

it will look like this below:

SignUp.getRoutes = function(cb) {
        var routes = [
            {
                method: 'post',
                path: '/actions/user/sign_up',
                auth_required: false,
                content_type: 'application/json',
                request_body: ['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data']
            }
        ];
        cb(null, routes);
    };