• Resolved waseemsoa

    (@waseemsoa)


    Hi,

    I am using selectbox for academic year and want to add 2024 automatically when 2024 will start

    I used this code and years from 1950 to 2023 loaded successfully but after form submission academic year field in user edit page( /wp-admin/user-edit.php ) were empty.

    <script type="text/javascript">
            window.onload = function () {
                //Reference the DropDownList.
                var ddlYears = document.getElementById("academic_year");
    
                //Determine the Current Year.
                var currentYear = (new Date()).getFullYear();
    
                //Loop and add the Year values to DropDownList.
                for (var i = 1950; i <= currentYear; i++) {
                    var option = document.createElement("OPTION");
                    option.innerHTML = i;
                    option.value = i;
                    ddlYears.appendChild(option);
                }
            };
        </script>

    Could you please send me proper code snippet which will work with dropdown.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support sanjuacharya77

    (@sanjuacharya77)

    Hi @waseemsoa,
    Thanks for writing in. Regarding your request, we need to consult the developer team. We will provide you with an update as soon as possible. Thank you for taking the time to contact us.

    Best regards!

    Plugin Support Sandip Pokhrel

    (@sandippokharel)

    Hi @waseemsoa

    Here is the required code snippet.
    add_filter( 'user_registration_select_frontend_form_data', function( $filter_data ) {
    $field_name = $filter_data['data']['general_setting']->field_name;
    if("select_1679464162" == $field_name ){
    $current_year = date("Y");
    $years_array = array();
    $years = array();
    for( $i=1950; $i<=$current_year;$i++) { $option = strval($i); $years_array[$option] = $option; array_push($years, $option); } $filter_data['form_data']['options'] = $years_array; $filter_data['data']['advance_setting']->options= implode(",", $years);
    }
    return $filter_data;
    });

    I hope this helps.

    Regards!

    Thread Starter waseemsoa

    (@waseemsoa)

    @sandippokharel

    sadly!

    this is still not working, select field still empty in user profile page “/wp-admin/user-edit.php”

    Plugin Support Sandip Pokhrel

    (@sandippokharel)

    Hi @waseemsoa

    Please add the following code to the prior one provided.

    /**
     * For Dynamic option in Admin's Edit Users section
     */
    add_filter( 'user_registration_profile_field_filter_select', function( $filter_data ) {
        
        $field_name = $filter_data['field']->general_setting->field_name;
        if("select_1674122530" == $field_name ){
            $current_year = date("Y");
            $years_array = array();
            for( $i=1950; $i<=$current_year;$i++) {
                $option = strval($i);
                $years_array[$option] = $option;
            }
            $filter_data['fields']['user_registration_select_1674122530' ]['options'] = $years_array;
        }
        return $filter_data;
    });

    Note: Replace the select_1674122530 with the field name of the select field on your form.
    I hope this helps.

    Regards!

    Thread Starter waseemsoa

    (@waseemsoa)

    @sandippokharel

    this code is still not working, select field still empty in user profile page “/wp-admin/user-edit.php”

    Plugin Support sanjuacharya77

    (@sanjuacharya77)

    Hi @waseemsoa,

    We did multiple tests on our environment and everything appears to be functioning correctly. I have attached a screen recording for your reference: https://encl.io/t/KPXbJJpHZSU#wwSk0QZWiO4hrHcAlBJTBg

    Can you please provide us with a screen recording of how you inserted the code we provided? Did you replace “select_1674122530” with the appropriate field name from your select field?

    In addition, here is a documentation guide that provides step-by-step instructions on how to add the custom code snippet to your site: https://docs.wpeverest.com/user-registration/docs/how-to-add-the-custom-code-snippet-on-your-site/

    Do let us know and I will get back to you.



Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Dynamically populate Year in DropDownList’ is closed to new replies.