• Resolved joshvic1

    (@joshvic1)


    Hi, I’m using forminator for my website.

    I run a site where I give points to users using mycred.

    I created an html field in my forminator form where I input [mycred_my_balance] so I can get the current user total points.

    But it seems the shortcode is not working, it’s just showing plain like that

    Can you help me

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hello @joshvic1

    I trust you’re doing well!

    An HTML field will not render the code that a shortcode generates. Out of the box it is not possible to use a shortcode inside the Forminator form.

    It can be done with some PHP coding. Please add this line inside your child theme’s functions.php file or use it as an mu-plugin:
    add_filter( 'forminator_replace_variables', 'do_shortcode' );

    If you do not have a child theme, please see here how to create it.

    To add it as an mu-plugin, create a file named forminator-render-shotycodes.php, add these lines inside:

    <?php
    add_filter( 'forminator_replace_variables', 'do_shortcode' );

    Upload this file to /wp-content/mu-plugins/ folder. If the mu-plugins folder doesn’t exist, please feel free to create it.

    Let us know how it went!

    Cheers,
    Nastia

    Thread Starter joshvic1

    (@joshvic1)

    Hi thanks

    It worked but the problem is it was only displayed at the frontend

    The number if points collected was not submitted at backend,though other details were submitted.

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello there @joshvic1

    HTML fields aren’t included in submissions, only in emails.

    I’ve already pinged our devs about it, so they can provide some more insights about it and possibly a hotfix. ??

    Thank you,
    Dimitris

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello @joshvic1

    Please create a new MU plugin file and insert the following code in there:

    <?php
    // Render shortcode on HTML fields
    add_filter( 'forminator_replace_variables', 'do_shortcode' );
    // Include shortcode output to hidden field
    add_filter( 'forminator_custom_form_submit_field_data', function( $field_data_array ){
        
        $form = array(
            'field' => 'hidden-1', // Form hidden field
            'shortcode' => '[mycred_my_balance]' // Shortcode to be rendered
        );
    
        foreach( $field_data_array as &$field_single ){
            if( $field_single['name'] === $form['field'] ){
                $field_single['value'] = strip_tags( do_shortcode( $form['shortcode'] ) );
            }
        }
    
        return $field_data_array;
    
    });

    How to: https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins

    Then include a Hidden field in your form and before saving data, the above code will replace its value with the content of the shortcode.

    Warm regards,
    Dimitris

    Thread Starter joshvic1

    (@joshvic1)

    Thanks a lot

    Also, is their a way the mycred balance can be automatically deducted once the form is submitted.

    Hello @joshvic1

    I hope you are doing well!

    This will require integration between the MyCred plugin and Forminator. Out of the box, it is not possible and can be achieved with custom coding.

    I’ve forwarded your question to our developers so they could provide some feedback. We will follow back in here once there will be an update.

    Have a good day!

    Cheers,
    Nastia

    Thread Starter joshvic1

    (@joshvic1)

    Sorry for my too much questions

    Lastly, I noticed the code you gave me is only possible with hidden fields.

    In a case where I need to use different shortcodes on different forms. How do I make that possible.

    For instance now..i have a form named (mycred form), let’s say that code works for that.

    I also have another form named (affiliate form) and I want to show one of the affiliate earnings on it also with this shortcode [affiliate_earnings status=”unpaid”]

    How do I get that done

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @joshvic1

    I hope you’re well today!

    If you only want to show/render shortcode output on front-end (e.g to show affiliate earnings) the solution that @wpmudev-support9 shared earlier here

    https://www.ads-software.com/support/topic/using-shortcode-in-forminator/#post-12368168

    will also work.

    You will just want to add a “HTML” field instead of a “Hidden” field to the form and put your shortcode into it (preferably through “Text” mode of editor).

    Best regards,
    Adam

    Hello @joshvic1

    I hope you are doing well!

    We haven’t heard back from you for a while now so we’ve marked this ticket as resolved. If you do have any followup questions or require further assistance feel free to reopen it and let us know here.

    Kind regards,
    Nastia

    I have the same issue – Trying to pass shortcode into hidden field in the forminator form. Tried adding the add_filter( ‘forminator_replace_variables’, ‘do_shortcode’ ); to the function file. and it did not work.

    We are not using MU plugin.

    See screenshot here: https://www.dropbox.com/s/58gp63a4glfptcw/2020-04-18_17-31-53.jpg?dl=0

    Cory

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @cory61574 ,

    The code you are using is only for the HTML field. If you want to use hidden fields, you need to use code provided here https://www.ads-software.com/support/topic/using-shortcode-in-forminator/#post-12413575

    kind regards,
    Kasia

    Is this only working for html field?
    I’m not able to use a shortcode in a label only in html field

    View post on imgur.com

    Was not easy but I think I did it ?? if someone elsee needs the code

    function forminator_callback($html) {
    	// WordPress does not like to use shortcodes in html attributes
    	preg_match_all('|(="\[.*\])(.*)(\[\/.*\])|U', $html, $matches);
    	$codes = $matches[0];
    
    	if (!$codes) {
    		return do_shortcode($html);
    	}
    
    	foreach ($codes as $code) {
    		$html = str_replace($code, do_shortcode($code), $html);
    	}
    	
    	return do_shortcode($html);
    }
    add_filter( 'forminator_render_fields_markup', 'forminator_callback' );

    I have implemented the MU plugin to use this in an HTML field. I’d like to use multiple shortcodes from custom user fields as items in a dropdown select in Forminator. Is this possible?

    @wpmudev-support2 @wpmudev-support9 @wpmudev-support8 @wpmudev-support6

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @briansuttongv

    I hope you’re well today!

    I’m not sure which of the codes mentioned in this thread have you implemented but the one shared above by @ckgrafico should actually allow shortcodes in all fields where you can only add them. Have you tried it already?

    https://www.ads-software.com/support/topic/using-shortcode-in-forminator/#post-12881666

    If it doesn’t work and/or you need any further assistance with this, please start a new thread of your own (as per this forum’s guidelines) and I and my colleagues we’ll be happy to work on this with you.

    Best regards,
    Adam

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Using shortcode in forminator’ is closed to new replies.