if ($companyform->is_cancelled() || $mform->is_cancelled()) {
    // Code by sumit
    redirect(new moodle_url('/blocks/iomad_company_admin/editusers.php'));
    // end of code
    /* if ($returnurl) {
       redirect($returnurl);
       } else {
       redirect($dashboardurl);
       } */
} else {
    if ($data = $mform->get_data()) {
        $data->userid = $USER->id;
        if ($companyid > 0) {
            $data->companyid = $companyid;
        }
        if (!($userid = company_user::create($data))) {
            $this->verbose("Error inserting a new user in the database!");
            if (!$this->get('ignore_errors')) {
                die;
            }
        }
        $user = new stdclass();
        $user->id = $userid;
        // GWL : to save custom profile fields data.
        $usernew = new stdclass();
        $usernew = $data;
        $usernew->id = $userid;
        profile_save_data($usernew);
        // GWL : to save custom profile fields data.
        // Check if we are assigning a different role to the user.
        if (!empty($data->managertype)) {