0

I have created a custom member field in the CP and set it to "required", "show in registration" and "show in profile". However, it doesn't show up in the form when I register a new member in the CP and it doesn't show up in their profile when I go to edit a member.

I can see that the field was created correctly because it is in the exp_member_fields table. Am I doing something wrong that it is not in the form to register anyone and that I can create a new member without filling out that field? I am not using any plugins currently (developing a new site).

Thanks for any help anyone can give!

2 Answers 2

0

It's a known bug that has been reported to Ellislab - https://support.ellislab.com/bugs/detail/21118/member-custom-fields-not-showing-on-profile-edit

0
0

Ok. I decided to look at this since we need this for our site. I have a fix for the new member registration page (not letting them be edited from the CP yet, that is next). Using EE3.0.0, in file system/ee/EllisLab/ExpressionEngine/Controller/Members/Create.php, there are two places that need to be changed.

To show fields, change function index() and add code to actually check for custom fields. Here is how I did it (I’m sure there are better ways):

Line 65 - 134 changed:

$tmp_final[] = array(
            'title' => 'member_group',
            'desc' => 'member_group_desc',
            'fields' => array(
                'group_id' => array(
                    'type' => 'select',
                    'choices' => $choices,
                    'value' => (isset($choices[5]) && $choices[5] == 'Members') ? 5 : '',
                    'required' => TRUE
                )
            )
        );
    $tmp_final[] = array(
            'title' => 'username',
            'fields' => array(
                'username' => array('type' => 'text', 'required' => TRUE)
            )
        );
    $tmp_final[] = array(
            'title' => 'mbr_email_address',
            'fields' => array(
                'email' => array('type' => 'text', 'required' => TRUE)
            )
        );
    $tmp_final[] = array(
            'title' => 'password',
            'desc' => 'password_desc',
            'fields' => array(
                'password' => array('type' => 'password', 'required' => TRUE)
            )
        );
    $tmp_final[] = array(
            'title' => 'password_confirm',
            'desc' => 'password_confirm_desc',
            'fields' => array(
                'confirm_password' => array('type' => 'password', 'required' => TRUE)
            )
        );

    //Get custom member fields 
    $cust_fields = ee()->db->from('member_fields')->where('m_field_reg', 'y')->order_by('m_field_id', 'asc')->get();

    if ($cust_fields->num_rows() > 0) {
        // Have custom fields. Add fields to registration form and for validation.
        foreach ($cust_fields->result_array() as $row)
        {
            if ($row['m_field_type'] == 'select') {
                $choices = array();
                $value = 0;
                $choice = explode("\n", $row['m_field_list_items']);
                $c = 0;
                foreach($choice as $choi) 
                {
                    $choices[$c] = $choi;
                    $c++;
                }   
            } else {
                $value = '';
            }   
            if ($row['m_field_required'] == 'n') 
                $required = FALSE;
            else 
                $required = TRUE;


            $tmp_final[] = array(
                'title' => $row['m_field_label'],
                'desc' => $row['m_field_description'],
                'fields' => array(
                    'field_id_'.$row['m_field_id'] => array(
                        'type' => $row['m_field_type'], 
                        'choices' => $choices,
                        'required' => $required,
                        'value' => $value
                    )
                )
            );
            if ($row['m_field_required'] == 'y') {
                $tmp_validation[] = array(
                     'field'   => 'field_id_'.$row['m_field_id'],
                     'label'   => $row['m_field_label'],
                     'rules'   => 'required'
                 );
            }
        }
    }
    $vars['sections'][] = $tmp_final;

    $tmp_validation[] = array(
             'field'   => 'group_id',
             'label'   => 'lang:member_group',
             'rules'   => 'required|integer|callback_valid_group_id'
        );
    $tmp_validation[] = array(
             'field'   => 'username',
             'label'   => 'lang:username',
             'rules'   => 'required|trim|valid_username'
        );
    $tmp_validation[] = array(
             'field'   => 'email',
             'label'   => 'lang:email',
             'rules'   => 'required|valid_email'
        );
    $tmp_validation[] = array(
            'field'    => 'password',
            'label'    => 'lang:password',
            'rules'    => 'required|valid_password[username]'
        );
    $tmp_validation[] = array(
             'field'   => 'confirm_password',
             'label'   => 'lang:confirm_password',
             'rules'   => 'required|matches[password]'
        );

    ee()->form_validation->set_rules($tmp_validation);

Next, to get the fields to actually be inserted into the database, a couple of changes need to be made in function register_member(), at lines 292-294:

if ($this->input->post(‘field_id_’.$row[‘m_field_id’]) !== FALSE) { $cust_fields[‘field_id_’.$row[‘m_field_id’]] = $this->input->post(‘field_id_’.$row[‘m_field_id’], TRUE); } since the names of the columns in exp_member_data have dropped the ‘m_’ prefix on the column names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.