0

We're using this registration plugin to serve as a registration form to new users subscribing to our site.

We have two (2) types of users:

  1. Students, and
  2. Employers.

Creating two different pages both with specific forms, we assigned the user role for each form to the two types such that:

on the Student Registration form, the user role is set to "Student" and on the Employer Registration form the user role is set to "Employer".

However, once registered, all users who register regardless of which form they used, are assigned the Student role.

This is because in Settings > General the New User Default Role is set to Student.

We want the forms to overwrite this default, so people who register an employer show up as an employer and not a student.

Is there any way to possibly achieve this?

0

I don't use this plugin for a while, don't you need to customize the shortcode for each form, one should be role="student" and the other one role="employer".

You can also use the filter

add_filter( 'simplr_validate_form', 'my_simplr_validate_form', 10, 3 );

A simple example, assuming the page for the registration is 1 for the student and 2 for employers, in functions.php :

add_filter( 'simplr_validate_form', 'my_simplr_validate_form', 10, 3 );
function my_simplr_validate_form($errors, $data, $atts){
    if(is_page(1)){
        $role = 'student';          
    }
    elseif(is_page(2)){
        $role = 'employer';          
    }
    else{
        $role = get_post_meta(get_the_ID(), 'simplr_role_lock', true);    
    }
    $atts['role'] = $role;

    return $atts;
}

For an eventually error message, that because the post(page) meta key "simplr_role_lock" does not match with the choosen role. So, you can try to unset $errors

add_filter( 'simplr_validate_form', 'my_simplr_no_errors', 10, 3 );
function my_simplr_no_errors($errors, $data, $atts){
    if(is_page(1) || is_page(2)){ 
         unset $errors;
    }      

    return $errors;
}

Be carefull : Untested !!!

  • I tried designating the role in the shortcode as you recommended but I get this error message: "Security: Role specified doesn't match form's designated role" – Jack Rogers Nov 4 '16 at 12:53
  • Because the role of the content doesn't match with a post meta. If you really have two forms in two different pages, try to change the meta value simplr_role_lock and set it to the role for the page. Other method, you can unset the $errors in another function called by the same filter (unset($errors); return $errors;). I will edit my answer in few minutes. – Benoti Nov 4 '16 at 13:04

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.