• Resolved desmogiec

    (@desmogiec)


    Hello there,
    I’ve created a form linked to a google sheet which is “reposted” on a discord server through ifttt similar.
    I wanted to know if is it possible to replace spaces from a text input into a hidden field, ie
    Input text {text-2), “I am an example”, written by the user compiling the form, become “I-am-an-example” in hidden field {hidden-1}.

    I’m already using a replacing custom mark in other forms, I thought that, maybe, this can be the solution also for this kind of request?
    The mu plugin that I’m using is this

    add_filter( 'forminator_field_markup', function( $html ) {
        $nickname = get_user_meta( wp_get_current_user()->ID, 'CustomMeta', true );
                $html = str_replace( '%nickname%', $nickname, $html );
    return $html;
    }, 99 );

    I’m using %nickname% as custom mark on a hidden field.

    Is it affordable through using mu-plugin like the example up here?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @desmogiec,

    I’m bringing this to our Forminator developer’s attention to see if there is any workaround that could be suggested based on your use case.

    Will keep you posted once we get further feedback asap.

    Kind Regards,
    Nithin

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @desmogiec

    Our developers replied, in case you are looking to replace a content from DB you can try this code:

    add_filter( 'forminator_cform_render_fields', function( $wrappers, $form_id ){
    	$your_form_id = 123;
    	if( $your_form_id == $form_id ){
    		$query_parameter = 'your_hidden_query_param_name';
    		$your_value = 'abc def ghi';
    		$_REQUEST[ $query_parameter ] = str_replace(' ', '-', $your_value);
    	}
    	return $wrappers;
    }, 10, 2 );

    But if you are looking to copy what user types to an hidden field you can try this code:

    add_action( 'wp_footer', function(){
    	?>
    	<script>
    		(function($){
    			$(function(){
    				let _form = $('#forminator-module-[your-form-id]');
    				if( _form.length ){
    					_form.find('#your-input-text-field-id').on('change', function(){
    						let _value = $(this).val();
    						if( _value ){
    							_form.find('#hidden-field-id').val( _value.replaceAll(' ','-') );
    						}
    					});
    				}	
    			})
    		})(window.jQuery);
    	</script>
    	<?php
    }, 21 );

    Let us know if the codes worked for you.
    Best Regards
    Patrick Freitas

    Thread Starter desmogiec

    (@desmogiec)

    Hello,
    thanks for the reply!

    I’ve tried the second one but apparently doesn’t work.
    Not sure if I’ve wrote the right ids

    <?php
    add_action( 'wp_footer', function(){
    	?>
    	<script>
    		(function($){
    			$(function(){
    				let _form = $('#forminator-module-[18041]');
    				if( _form.length ){
    					_form.find('#forminator-field-text-2').on('change', function(){
    						let _value = $(this).val();
    						if( _value ){
    							_form.find('#forminator-field-text-3').val( _value.replaceAll(' ','-') );
    						}
    					});
    				}	
    			})
    		})(window.jQuery);
    	</script>
    	<?php
    }, 21 );

    I’ve found those ids by using the console in firefox.
    For testing purpose I’ve made a specular input text to see if something happens, to be changed in hidden when it works.

    Stupid question, this is working “live”, right?
    When I type in text-2, it should appear in text-3 with replaced spaces instantly..?

    Thread Starter desmogiec

    (@desmogiec)

    Ok, I noticed that [] are not to be used, so I have that portion of code working now.

    let _form = $(‘#forminator-module-18041’);
    if( _form.length ) {
    […]

    The second part of the code, still get no results at all

    _form.find('#forminator-field-text-2').on('change', function(){
    	let _value = $(this).val();
    	if( _value ){
    		_form.find('#forminator-field-text-3').val( _value.replaceAll(' ','-') );
    	}

    Am I using wrong ids?

    • This reply was modified 2 years, 6 months ago by desmogiec.
    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @desmogiec,

    I gave a quick test and the code does work fine on my site when checked, it does work fine with Text and hidden fields and also with two text fields.

    This was what I tested:

    <?php
    
    add_action( 'wp_footer', function(){
    	?>
    	<script>
    		(function($){
    			$(function(){
    				let _form = $('#forminator-module-5150');
    				if( _form.length ){
    					_form.find('#forminator-field-text-1').on('change', function(){
    						let _value = $(this).val();
    						if( _value ){
    							_form.find('#forminator-field-text-2').val( _value.replaceAll(' ','-') );
    						}
    					});
    				}	
    			})
    		})(window.jQuery);
    	</script>
    	<?php
    }, 21 );
    

    Maybe the above code might give you a better idea of what might be missed.

    I hope this helps. Have a nice day ahead.

    Kind Regards,
    Nithin

    Thread Starter desmogiec

    (@desmogiec)

    Ok, I got it.
    The problem was that I’ve made the form loading in ajax.
    Disabling it has solved the issue.
    Now it’s working fine 🙂

    What if I want to use that even on ajax loading?
    (I’ve been using ajax since some of our users reported that from iphone forms didn’t work properly, issues that didn’t come out when using ajax..)

    Big thanks for now 🙂

    Plugin Support Pawel – WPMU DEV Support

    (@wpmudev-support9)

    Hello @desmogiec !

    In this case the alternative to using Ajax would be to use the other option instead – to prevent caching on the pages with the form on them and it should work without any issues as well.

    Kind regards,
    Pawel

    Plugin Support Kasia – WPMU DEV Support

    (@wpmudev-support2)

    Hello @desmogiec ,

    We haven’t heard from you for several days now, so it looks like you don’t have more questions for us.

    Please feel free to re-open this ticket if needed.

    Kind regards,
    Kasia

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Replace input text spaces to “-” in a hidden field’ is closed to new replies.