• Resolved bobloblawvegas

    (@bobloblawvegas)


    A dynamically populated Ninja Forms list/select field submits normally under 3.14.8. Under 3.14.9, the identical form and plugins return “Invalid selection” for that list field. Conditional/hidden fields also become visible after the failed validation. Rolling back only Ninja Forms to 3.14.8 immediately resolves both issues.

Viewing 6 replies - 1 through 6 (of 6 total)
  • jeanmicheljunod

    (@jeanmicheljunod)

    same problem here, ninja_forms_render_options is used for form display, but not for datas validations.

    Our form stopped working since 3.14.9 with this “Invalid selection” error.

    Please give a hook to be able to validate custom/on-the-fly options or the ability to disable validation.

    serge417

    (@serge417)

    Same problem here.

    Faisal Ahammad

    (@faisalahammad)

    Hi everyone,

    I looked into this and built a small fix you can add to your site. No need to edit the plugin files, so it will keep working after updates.

    In version 3.14.9 Ninja Forms added a security check for list and radio fields. Now when a form is submitted, it checks the chosen value against the saved options list.

    The problem is that this check uses the options saved in the database. It does not run the ninja_forms_render_options filter, which is the one most of us use to fill the list on the fly (for example from posts, a custom post type, or an API).

    So the user sees the option in the dropdown and picks it, but on submit the value is not in the saved list, and Ninja Forms says “Invalid selection.” The hidden fields also come back because the form did not finish.

    Rolling back to 3.14.8 works because that check did not exist before.

    We can use the ninja_forms_pre_validate_field_settings hook to run the same render filter on the validation side too. This way the check sees the same options the user saw. The security check stays in place, only real options pass. It touches only the listselect and listradio fields.

    Create a file at wp-content/mu-plugins/nf-3149-invalid-selection-fix.php and paste this inside:

    <?php
    /**
    * Plugin Name: Ninja Forms 3.14.9+ "Invalid selection" Fix
    * Description: Makes dynamically-populated listselect/listradio options pass validation again after the 3.14.9 option-whitelist change. No core file edits; survives plugin updates.
    * Version: 1.0.0
    * Author: Faisal Ahammad
    */

    if ( ! defined( 'ABSPATH' ) ) {
    exit;
    }

    add_filter( 'ninja_forms_pre_validate_field_settings', 'nf_3149_fix_render_options_at_validation' );

    function nf_3149_fix_render_options_at_validation( $field ) {
    if ( ! isset( $field['type'] ) ) {
    return $field;
    }
    if ( 'listselect' !== $field['type'] && 'listradio' !== $field['type'] ) {
    return $field;
    }
    if ( ! isset( $field['options'] ) || ! is_array( $field['options'] ) ) {
    return $field;
    }

    $field['options'] = apply_filters( 'ninja_forms_render_options', $field['options'], $field );
    $field['options'] = apply_filters( 'ninja_forms_render_options_' . $field['type'], $field['options'], $field );

    return $field;
    }

    If you prefer, you can also paste the function part into your child theme functions.php or a small custom plugin. Just do not edit files inside the ninja-forms folder, those get overwritten on update.

    Give it a try, and let me know how that goes!

    Best regards,
    Faisal (forum volunteer)

    Thanks Faisal, it worked!

    You’re welcome, @mister_r. I’m glad to hear it worked for you.

    Plugin Support Mia

    (@xmiax)

    Hi

    Thanks for reaching out.

    As we mention at the pinned post in the top of the forum we offer support, free and paid alike, on our site. That is the fastest way to get help.

    Also please note that we do not support custom code. If you don’t let us know that you have implemented custom code when reaching out for support, your support ticket will take longer to resolve.

    Thanks

    Mia

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.