function application_user_signup($user)
{
    // Derived from email->user_signup
    global $CFG, $PAGE, $OUTPUT;
    $user->password = hash_internal_user_password($user->password);
    if (empty($user->calendartype)) {
        $user->calendartype = $CFG->calendartype;
    }
    $user->id = user_create_user($user, false, false);
    // Save any custom profile field information
    profile_save_data($user);
    // Save contact information
    write_contact_details($user->id, $user);
    // Trigger event
    \core\event\user_created::create_from_userid($user->id)->trigger();
    if (!send_application_confirmation_email($user)) {
        print_error('auth_emailnoemail', 'auth_email');
    }
    $PAGE->set_title($CFG->pageheading . ': ' . get_string('emailconfirm'));
    echo $OUTPUT->header();
    notice(get_string('emailconfirmsent', '', $user->email), $CFG->wwwroot . '/local/obu_application/login.php');
}
require_once './contact_form.php';
require_obu_login();
$home = new moodle_url('/local/obu_application/');
$url = $home . 'contact.php';
$PAGE->set_title($CFG->pageheading . ': ' . get_string('contactdetails', 'local_obu_application'));
// HTTPS is required in this page when $CFG->loginhttps enabled
$PAGE->https_required();
$PAGE->set_url($url);
$message = '';
$counties = get_counties();
$parameters = ['user' => read_user($USER->id), 'applicant' => read_applicant($USER->id, false), 'counties' => $counties];
$mform = new contact_form(null, $parameters);
if ($mform->is_cancelled()) {
    redirect($home);
} else {
    if ($mform_data = $mform->get_data()) {
        if ($mform_data->submitbutton == get_string('save', 'local_obu_application')) {
            $mform_data->county = $counties[$mform_data->domicile_code];
            write_user($USER->id, $mform_data);
            write_contact_details($USER->id, $mform_data);
        }
        redirect($home);
    }
}
echo $OUTPUT->header();
if ($message) {
    notice($message, $home);
} else {
    $mform->display();
}
echo $OUTPUT->footer();