• 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 15 replies - 1 through 15 (of 22 total)
  • @ayana24797

    Why are you using a shortcode?

    Apply custom validation to a field

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

    Thread Starter Ayana Memon

    (@ayana24797)

    i know i tried this but it’s not working,
    i create short code in functions.php file after use it in the ultimate member registration form.
    field->shortcode.

    @ayana24797

    Can you show us the code snippet you used after reading the documentation about field validation?

    Thread Starter Ayana Memon

    (@ayana24797)

    sure

    add_action('um_submit_form_errors_hook_','um_custom_validate_form', 999, 1);
    function um_custom_validate_form( $shortcode_args ) {
        global $ultimatemember;
    
        $teacher_country = $shortcode_args['um_shortcode_10774_11'];
    
        if ( !strstr( $teacher_country, " " )){
            $ultimatemember->classes['form']->add_error( 'teacher_country', 'You must register this field.' );
        }
    }

    this code i used..

    @ayana24797

    You have the field with the label: “Bitte w?hlen Sie das Land/die Region, von dem/der aus Sie am Projekt teilnehmen.” as required, why do you need to validate this field again in the code snippet?

    Can you show us the shortcode also?

    Thread Starter Ayana Memon

    (@ayana24797)

    “Bitte w?hlen Sie das Land/die Region, von dem/der aus Sie am Projekt teilnehmen.” as required
    yes it’s required but isn’t working at the time of registration na.. that is issue..

    Can you show us the shortcode also?
    SURE..

    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>';
    
    	return $html;
    }
    add_shortcode( 'my_countries', 'my_countries_func' );

    @ayana24797

    When I test the Country field as required on my site I get the error message: “Country is required”.

    Let’s find out why your country field is not being rejected if no country is selected.

    When trying to register at your site I get this Javascript error: Cannot read properties of null (reading 'dataset') in the function umHideLinks()

    You have some scripts from a CDN, turn off the CDN caching.

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

    (@ayana24797)

    yes i added CDN Links
    and yes Cannot read properties of null (reading ‘dataset’) this error is occurring.

    Thread Starter Ayana Memon

    (@ayana24797)

    I am only doing some changes..
    This site is alrady readymade.
    I am just changing Some parts or making it dynamic..

    Thread Starter Ayana Memon

    (@ayana24797)

    any possibilities are available to put validation on shortcode?
    @missveronicatv

    @ayana24797

    With the Shortcode and the Validation you are doing what the default Country field in UM Forms Designer is designed to do. Remove Shortcode and Validation and use the UM Forms Designer and we solve any issues withe this UM Field.

    Thread Starter Ayana Memon

    (@ayana24797)

    @missveronicatv
    but country has a dependency..
    and i use shortcode to make it dynamic..
    in the shortcode we can do validation? any option is available..?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @ayana24797

    Why not use a dropdown field with a custom callback to populate the options with your custom function? In this way, you will be able to validate the field.

    Please see this: https://docs.ultimatemember.com/article/1539-choices-callback-feature-in-um-2-1

    Regards,

    Thread Starter Ayana Memon

    (@ayana24797)

    @champsupertramp
    hello,
    but i almost complete this and it’s use in multiple place now at the end moment how i can change it?
    if there have any option available with shortcode then please let me know..

    • This reply was modified 3 years, 1 month ago by Ayana Memon.
Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Add validation on short code at the registration time in ultimate member plugin’ is closed to new replies.