• Resolved ijlwebsolutions

    (@ijlwebsolutions)


    I want to create a dropdown, so when they select an option it jumps straight to that URL. These used to be called a ‘jump menu’. It works just like a sub-menu does, but uses a drop-down field.

    In this case I want them to select a location from a drop-down field, and then this takes them straight to the relevant page/URL.

    It’s very simple, but for some reason I can’t see how to do it with a Forminator drop-down field

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ijlwebsolutions

    I hope you’re well today!

    Forminator doesn’t have such function built-in currently. It’s mostly meant for gathering data from users via forms rather than creating menus and most use-cases include multiple fields and manual form submission.

    However, you can achieve that with a bit of additional code. Basic example would be as follows:

    1. create a form with “select” type filed on it

    – make sure that there are as many options as your target redirect URLs + one “Please select” or similar option at the top (that’s because the default first option will not trigger submission)

    – do not put URLs in select option

    2. then add as many “Submission Behaviors” (on “Behavior” page of the form settings) as you have redirects; each behavior should be of “Redirect user to URL” type where you set target URL

    3. for each of those behaviors set “condition” based on selected option in select field.

    This way depending on which option user selected, they’ll be redirected to different URLs.

    4. then add this code to the site as MU plugin:

    <?php 
    
    add_action( 'wp_footer', 'wpmudev_form_submit_automatic', 9999 );
    function wpmudev_form_submit_automatic(){
        global $post;
        if ( is_a( $post, 'WP_Post' ) && !has_shortcode($post->post_content, 'forminator_form') ) {
            return;
        }
    	?>
    	<script type="text/javascript">
    	jQuery( document ).ready( function($){
    		setTimeout(function() {
    			$('.forminator-custom-form').trigger('after.load.forminator');
    		}, 100);
    		$(document).on('after.load.forminator', function(e, form_id) {
    			if ( e.target.id == 'forminator-module-3150' ) { //Please change the form ID
                    $('#select-1 select').on('select2:select', function(e) {  //Please change the select field ID
    					$('.forminator-button.forminator-button-submit').click();
    				});
    			    
    			}
    		});
    	});
    	</script>
    	<?php
    }

    – create an empty file with a .php extension (e.g. “forminator-jump-redirect.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install

    – put above code into it

    – in this line

    if ( e.target.id == 'forminator-module-3150' ) { //Please change the form ID

    replace number 3150 with ID of your form (form ID is the number you can see in form’s shortcode)

    – and in this line

    $('#select-1 select').on('select2:select', function(e) { //Please change the select field ID

    replace #select-1 with your select field ID if it’s different.

    – save the file and that’s it.

    Once you put your form in some post or page, changing selection should automatically redirect user to designated URL.

    Note: if you wish to hide Submit button also, you will need to add this CSS to the site (do NOT use buttons “visibility” conditions to hide it – code wouldn’t work):

    #forminator-module-3150 .forminator-button-submit {
    	visibility:hidden!important;mportant;
    }

    Again, replace number 3150 with your form ID.

    Best regards,
    Adam

    Thread Starter ijlwebsolutions

    (@ijlwebsolutions)

    Great, thank you

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Forminator – jump menu’ is closed to new replies.