• Resolved utkarshs

    (@utkarshs)


    Hello, I want to validate the text field against database. I want the input text field to accept number only if it’s present in the database.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @utkarshs

    I’m not sure what you mean by testing against the Database. Are you trying to create your own validation before saving the input value to the db table?

    Regards,

    Thread Starter utkarshs

    (@utkarshs)

    Yes, I want to save the input value if it’s present in database. Is it possible through ultimate member or if any other plugin you know about? FYI, I have built the registration and profile with ultimate member.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @utkarshs

    Unfortunately, this requires customization on your end.

    Here’s a sample code that validate a specific field on form submission:

    function um_custom_validate_english_name( $key, $array, $args ) {
        
        if ( preg_match('/[^A-Za-z0-9]/', $args[$key] ) )  {
            UM()->form()->add_error( $key, __( 'Please use only English letters.', 'ultimate-member' ) );
        }
        // add your custom validation 
    
    }
    add_action( 'um_custom_field_validation_english_name', 'um_custom_validate_english_name', 30, 3 );

    english_name is the field key. You can change it with your field key. The following line will let you display an error when the field is invalid:
    UM()->form()->add_error( $key, __( 'Please use only English letters.', 'ultimate-member' ) );

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @utkarshs

    ..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,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Validate text field input against database’ is closed to new replies.