Make Custom Fields for User Profile Required Instead of Optional Make Custom Fields for User Profile Required Instead of Optional
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Make Custom Fields for User Profile Required Instead of Optional

Started by Guidonzolo, February 07, 2011, 08:32:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guidonzolo

Hello,
I'm finding a way to make custom fields of user profile required. I've find some solution for Coppermine 1.4 but, with the last version 1.5.12, I think there are some changes because i'm not able to follow the suggests for the 1.4x version.
Can anyone help me?
Thanks
Guidonzolo

Αndré


Guidonzolo

Thanks for you replay.
I've posted on 1.5 because of i've the last version. The threads that i've read on 1.4 forum refer about a register.php page that is different from the register.php of the last version.
Guido S

Αndré


Guidonzolo


Αndré

The instructions from that thread still applies, but the code has slightly changed, so you shouldn't search for the exact code Sami referred to.

Which custom fields do you want to make mandatory?

Guidonzolo

I want to make mandatory the first custom field. This field is "Full Name", because on my site, i allow access only to my friends.
Thanks

Guido

Αndré

Open register.php, find
    $form_data = array(
        array('label', $lang_register_php['required_info']),
        array('input', 'username', $icon_array['username'] . $lang_register_php['username'], 25),
        array('password', 'global_registration_pw', $icon_array['password'] . $lang_register_php['global_registration_pw'], 25),
        array('password', 'password', $icon_array['password'] . $lang_register_php['password']),
        array('password', 'password_verification', $icon_array['password'] . $lang_register_php['password_again']),
        array('input', 'email', $icon_array['email'] . $lang_register_php['email'], 255),
        array('label', $lang_register_php['optional_info'])
    );
    $optional_data = 0;
    if ($CONFIG['user_profile1_name'] != '') {
        $form_data[] = array('input', 'user_profile1', $icon_array['blank'] . $CONFIG['user_profile1_name'], 255);
        $optional_data++;
    }

and replace with
    $form_data = array(
        array('label', $lang_register_php['required_info']),
        array('input', 'username', $icon_array['username'] . $lang_register_php['username'], 25),
        !empty($CONFIG['global_registration_pw']) ? array('password', 'global_registration_pw', $icon_array['password'] . $lang_register_php['global_registration_pw'], 25) : '',
        array('password', 'password', $icon_array['password'] . $lang_register_php['password']),
        array('password', 'password_verification', $icon_array['password'] . $lang_register_php['password_again']),
        array('input', 'email', $icon_array['email'] . $lang_register_php['email'], 255),
        !empty($CONFIG['user_profile1_name']) ? array('input', 'user_profile1', $icon_array['blank'] . $CONFIG['user_profile1_name'], 255) : '',
        array('label', $lang_register_php['optional_info'])
    );
    $optional_data = 0;


find
$profile1 = $superCage->post->getEscaped('user_profile1');
and replace with
$profile1 = trim(get_post_var('user_profile1'));

find
    if ($password != $password_again) {
        $error .= '<li style="list-style-image:url(images/icons/stop.png)">' . $lang_register_php['password_verification_warning1'] . '</li>';
    }

below, add
    if (utf_strlen($profile1) < 2) {
        $error .= '<li style="list-style-image:url(images/icons/stop.png)">Value \'' . $CONFIG['user_profile1_name'] . '\' must be at least two characters long!</li>';
    }



If you want to show an error message before the form will be submitted, open register.php, find
            if (isset($lang_register_php[$element[1].'_warning2']) == TRUE) {
                $warning2 = '<div id="'.$element[1].'_warning2" class="cpg_message_validation formFieldWarning" style="display:none;">' . $lang_register_php[$element[1].'_warning2'] . '</div>';
            } else {
                $warning2 = '';
            }

below, add
            if ($element[1] == 'user_profile1') {
                $warning1 = '<div id="user_profile1_warning1" class="cpg_message_validation formFieldWarning" style="display:none;">';
                $warning1 .= 'The ' . $CONFIG['user_profile1_name'] . ' mustn\'t be empty!';
                $warning1 .= '</div>';
                $warning2 = '<div id="user_profile1_warning2" class="cpg_message_validation formFieldWarning" style="display:none;">';
                $warning2 .= 'The ' . $CONFIG['user_profile1_name'] . ' must be at least two characters long!';
                $warning2 .= '</div>';
            }


open js/register.js, find
    if (errors != 0) {
        $('#form_not_submit_top').show();
        $('#form_not_submit_bottom').show();
        return false;
    } else {
        return true;
    }

above, add
    // Check user_profile1
    if($('#user_profile1').val() == '') {
        $('#user_profile1_warning1').show();
        errors++;
    } else {
        if ($('#user_profile1').val().length < 2 ) {
            $('#user_profile1_warning2').show();
            errors++;
        }
    }


Guidonzolo


Αndré

Marking accordingly. Please do that yourself in the future.

Αndré