• Resolved dgoethals

    (@dgoethals)


    Hi,

    In the registration form, I’ve put a numeric field with:
    – no default value
    – min value: 0
    – max value: 7
    – validation: numeric value only
    The intent is to allow 0, 1, 2, 3, 4, 5, 6 or 7.

    When the user fills in the form, a validation error is thrown when the user inputs the value 0.

    Any clue would be helpful.

    Regards

Viewing 15 replies - 1 through 15 (of 17 total)
  • @dgoethals

    I tried but can’t reproduce you validation error for the selection of a 0.

    What exact error message do you get?

    What happens if you don’t use the “Numeric value only” validation and use “None” for validation?

    The default “Number” setup field with min and max values is already restricted to default numbers and “Numeric value only” validation might be more relevant for numbers in text fields.

    Thread Starter dgoethals

    (@dgoethals)

    Thanks a lot for your answer @missveronicatv.

    It just says “<field_label> is mandatory”:
    – if no choice has yet been done
    – when selecting 0 with the arrow or typing it

    I removed the “Numeric value only” validation but got the same message.

    If I uncheck “Mandatory”, the min value 0 is put in the field.

    If I put a min value of 1 (and keep field mandatory), the min value of 1 passes validation.

    @dgoethals

    I can’t find the text string “is mandatory” or “Mandatory” anywhere in the core UM sources.

    Which English translation are you using and which version of UM?

    @dgoethals

    I can read from your Post history that you are comparing two membership plugins.
    Can you deactivate the other membership plugin for your UM tests.

    Thread Starter dgoethals

    (@dgoethals)

    @missveronicatv

    Indeed I tested other plugins but finally kept only UM. All others are deactivated and uninstalled.
    Sorry if the translation is not accurate, I’m working with WordPress in French.
    A copy of the settings of this numeric field can be seen there: https://imgur.com/c1DFuvl
    It can be temporarily tested there: https://global.toutchat-toutmoi.com/register/
    Just click on the button at the bottom and you’ll see all validation errors, incl. the “Nombre” field (near the bottom of the page).

    @dgoethals

    Can you turn off ModSecurity in cPanel.

    Thread Starter dgoethals

    (@dgoethals)

    Yes, done

    @dgoethals

    It seems like a conflict with another plugin or your theme.

    Follow these steps for a conflict test:

    https://docs.ultimatemember.com/article/96-how-to-do-a-plugin-theme-conflict-test

    Thread Starter dgoethals

    (@dgoethals)

    @missveronicatv

    I switched to theme Twenty fifteen and kept only 1 plugin: UM.

    The problem still occurs.

    @dgoethals

    You have four additional submit buttons on the page:

    Search
    Search
    Refuser
    Accepter

    Can you remove them for a test of the Registration form.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @dgoethals

    ..This thread has been inactive for a while so we’re going to go ahead and mark it Resolved…

    ..Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help… ??

    Regards,

    Thread Starter dgoethals

    (@dgoethals)

    Hi,

    I’ve installed the latest version (5.8.2) of a French WordPress on a local machine.
    Theme: Twenty fifteen – Search Widget removed (the only submit button on the page is the UM one)
    1 extension active: UM
    I’ve added a numeric field to the default UM registration form:
    – mandatory
    – max value 100
    – min value: left empty
    – validation: none
    I can choose -2, -1, 1, 2… But if I choose 0, I got the message telling me that this field is mandatory.

    I’ve added a text box to the same form:
    – mandatory
    – min. length: 0
    – max. length: 3
    – validation: numeric value only
    I can type any numeric value: -1, 0, 1…
    It may seems to be OK, but this number should represent a number of children (negative values excluded thus) and I want to be sure that the user did not forget to indicate the value and did not use a default one.
    Any clue on how to achieve this?

    Your help is more than welcome. Thanks

    @dgoethals

    What is the operating system at your web hosting?

    I have made a code snippet based on your explanation of this issue with the number 0.

    First:
    Install the code snippet by adding to your child-theme functions.php file or use the “Code Snippets” plugin.
    Change my test meta_key name from ‘my_um_number’ to your meta_key name.
    Change the error message from ‘Error message’ to your message.

    Second:
    Modify your number field in UM Forms designer to use the code snippet for validation:
    – select “Custom Validation”
    – enter “number_zero_seven” in the “Custom Action” field.

    Reference:
    https://docs.ultimatemember.com/article/94-apply-custom-validation-to-a-field

    add_action('um_submit_form_errors_hook_','um_custom_validate_number_zero_seven', 999, 1);
    function um_custom_validate_number_zero_seven( $args ) {
    	$meta_key = 'my_um_number';
    	if ( !empty( $args[$meta_key] )) {
               $number = intval( trim( $args[$meta_key] ));
               if( $number === false || $number < 0 || $number > 7 ) {
                  UM()->form()->add_error( $meta_key, 'Error message' );
               }
    	} 
    }
    • This reply was modified 3 years, 3 months ago by missveronica.
    • This reply was modified 3 years, 3 months ago by missveronica.
    Thread Starter dgoethals

    (@dgoethals)

    Thanks a lot @missveronicatv. It works perfectly.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know how it resolves the issue.

    Regards,

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Validation error for 0 in numeric field’ is closed to new replies.