• Resolved Ayana Memon

    (@ayana24797)


    Hello,
    i need a help on custom shortcode validation in registration please suggest me,
    how i can do validation..?

    Thank You.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 16 through 22 (of 22 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @ayana24797

    Try the following code snippet. It should display the error below the dropdown field:

    function my_countries_func() {
    	$country_post = (new WP_Query(['post_type' => 'all_country', 'post_status' => 'publish', 'order' => 'ASC', 'posts_per_page' => -1]));
    	
    	$options = '';
    	if ( $country_post->have_posts() ): 
    		while ( $country_post->have_posts() ) :  $country_post->the_post(); 			
    			$options .='<option value="'.get_the_id().'">'.get_the_title().'</option>';					
    		endwhile;
    	endif; 
    
    	$html = '<div class="um-field-label"><label for="um-field-shortcode">'.__( 'Bitte w?hlen Sie das Land/die Region, von dem/der aus Sie am Projekt teilnehmen.*', 'ultimate-member' ).'</label></div> ';	
    	$html .= '<div class="um-field-area">
    				<select class="um-form-field js-states valid form-control" name="teacher_country" id="my_country" onclick="get_all_city(this.value)" required>
    					<option value= " ">Bitte w?hlen Sie ein Land</option>
    					'.$options.'
    					<option value="new_country" id="other_country">Anderes Land</option>
    				</select>
    			</div>';
    
    if ( UM()->fields()->is_error( 'teacher_country' ) ) {
    	$html .=  UM()->fields()->field_error( UM()->fields()->show_error( 'teacher_country' ), true );
    } 
    
    	return $html;
    }
    add_shortcode( 'my_countries', 'my_countries_func' );
    
    add_action('um_submit_form_errors_hook_','um_custom_validate_form', 999, 1);
    function um_custom_validate_form( $shortcode_args ) {
      
        $teacher_country = $shortcode_args['um_shortcode_10774_11'];
    
        if ( !strstr( $teacher_country, " " )){
            UM()->form()->add_error( 'teacher_country', 'You must register this field.' );
        }
    }
    

    Regards,

    Thread Starter Ayana Memon

    (@ayana24797)

    @champsupertramp
    hii,
    yet not working ??

    if ( UM()->fields()->is_error( 'teacher_country' ) ) {
        $html .=  UM()->fields()->field_error( UM()->fields()->show_error( 'teacher_country' ), true );
    }
    • This reply was modified 3 years, 1 month ago by Ayana Memon.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @ayana24797

    Please try the following:

    function my_countries_func() {
    	$country_post = (new WP_Query(['post_type' => 'all_country', 'post_status' => 'publish', 'order' => 'ASC', 'posts_per_page' => -1]));
    	
    	$options = '';
    	if ( $country_post->have_posts() ): 
    		while ( $country_post->have_posts() ) :  $country_post->the_post(); 			
    			$options .='<option value="'.get_the_id().'">'.get_the_title().'</option>';					
    		endwhile;
    	endif; 
    
    	$html = '<div class="um-field-label"><label for="um-field-shortcode">'.__( 'Bitte w?hlen Sie das Land/die Region, von dem/der aus Sie am Projekt teilnehmen.*', 'ultimate-member' ).'</label></div> ';	
    	$html .= '<div class="um-field-area">
    				<select class="um-form-field js-states valid form-control" name="teacher_country" id="my_country" onclick="get_all_city(this.value)" required>
    					<option value= " ">Bitte w?hlen Sie ein Land</option>
    					'.$options.'
    					<option value="new_country" id="other_country">Anderes Land</option>
    				</select>
    			</div>';
    
    if ( UM()->fields()->is_error( 'teacher_country' ) ) {
    	$html .=  UM()->fields()->field_error( UM()->fields()->show_error( 'teacher_country' ), true );
    } 
    
    	return $html;
    }
    
    add_action('um_submit_form_errors_hook_','um_custom_validate_form', 1, 1);
    function um_custom_validate_form( $shortcode_args ) {
      
        $teacher_country = $_REQUEST['teacher_country'];
    
        if ( empty( $teacher_country ) ){
            UM()->form()->add_error( 'teacher_country', 'You must register this field.' );
        }
    }

    Regards,

    • This reply was modified 3 years, 1 month ago by Champ Camba.
    Thread Starter Ayana Memon

    (@ayana24797)

    Hii, @champsupertramp

    this also isn’t working…

    • This reply was modified 3 years, 1 month ago by Ayana Memon.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @ayana24797

    I suggest that you use the Choices/Dropdown callback function to populate it with countries. You can use this code to add a callback function:

    function my_countries() {
    	$country_post = (new WP_Query(['post_type' => 'all_country', 'post_status' => 'publish', 'order' => 'ASC', 'posts_per_page' => -1]));
    	$arr_countries = array();
    	if ( $country_post->have_posts() ): 
    		while ( $country_post->have_posts() ) :  $country_post->the_post(); 			
    			$arr_countries[ get_the_ID() ] = get_the_title(); 				
    		endwhile;
           endif;
         
          return $arr_countries;
    }
    

    Add this my_countries in the dropdown settings as a choices callback function. Please see the guide in the link: https://docs.ultimatemember.com/article/1539-choices-callback-feature-in-um-2-1

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @ayana24797

    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,

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hey there!

    This thread has been inactive for a while, so we will 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. ??

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Add validation on short code at the registration time in ultimate member plugin’ is closed to new replies.