• Bhushan

    (@bhushansbobade20)


    Hi,

    I want to check values input field (Eg. Guest WinnerID) from profile edit form with pre entered field of registration form (Eg. WinnerID) from database. If the Guest WinnerID value == WinnerID value then submit profile from.

    Will you please help me here. Anyone?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • after you add a field you can go under Validation and scroll down to “Custom Validation”

    after that is done you will have to find a UM hook (code) that does what you want.

    Custom Validation Hook (code) function

    Thread Starter Bhushan

    (@bhushansbobade20)

    Ok do you have any example to refer for Custom Validation. In my case, I want “Unique Meta Key validation” and compare value with other field as well. Any suggestion on this case.

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hi @bhushansbobade20,

    Please see this code sample for additional info.

    Regards.

    Thread Starter Bhushan

    (@bhushansbobade20)

    Hi UM support,

    Thanks for reply!

    add_action('um_submit_form_errors_hook_','um_custom_validate_username', 999, 1);
    function um_custom_validate_username( $args ) {
    	global $ultimatemember;
    	
    	if ( isset( $args['guest_winner_id'] ) && strstr( $args['guest_winner_id'], $args['winner_id'] ) ) {
    		$ultimatemember->form->add_error( 'guest_winner_id', 'This Winner ID does not exist.' );
    	}
    }

    Above is the code i am trying to use but its not working.

    On User profile update I want to compare value input field (Eg. Guest WinnerID) from profile edit form with pre entered field of registration form WinnerID from database.

    If the Guest WinnerID value FOUND in WinnerID value then submit profile from.

    Will you please help me here how should i update the custom code PLEASE!!

    Thread Starter Bhushan

    (@bhushansbobade20)

    I made it and it worked.

    To achive my case I have used custom field validation hook and also I have compared unique mata key value

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

    Below is the code:

    add_action('um_custom_field_validation_winner_id_exist','um_custom_field_validation_winner_id_exist', 10, 3);
    function um_custom_field_validation_winner_id_exist( $key, $array, $args ) 
    {
    	global $ultimatemember;  
    	$args_unique_meta = array(
            'meta_key' => $key,
            'meta_value' => $args['guest_winner_id'],
            'compare' => '='
        );
    
        $meta_key_exists = get_users( $args_unique_meta );
        
        if ( (isset( $args['guest_winner_id'] ) && username_exists( $args['guest_winner_id'] ) == false ) || $meta_key_exists  ) 
    	{
    		$ultimatemember->classes['form']->add_error($key, 'This Winner ID does not exist or already used.');
    	}
    }
    

    Thanks & Regards!
    BB

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Validation’ is closed to new replies.