Title: running shortcode in html field
Last modified: August 7, 2022

---

# running shortcode in html field

 *  Resolved [narcisF](https://wordpress.org/support/users/filipnarcis/)
 * (@filipnarcis)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/)
 * Hi,
    I tried do run a shortcode in a html field, it works but doesn’t executes
   the javascript part. The shortcode is for tabblespress tables as you can see 
   in example link below:
 * in this link [https://www.pm.webinspire.ro/depunere-online/](https://www.pm.webinspire.ro/depunere-online/)
   it’s a table resulted from the shortcode and when you press next button (Urmatoarea)
   it doesn’t work. If I try to execute shortcode not in a form, it works: [https://www.pm.webinspire.ro/sample-page/](https://www.pm.webinspire.ro/sample-page/)
 * As I figured it out it seems that the javascript code is stripped or not executed.
   I also used this add_filter( ‘forminator_replace_variables’, ‘do_shortcode’ );
   
   Can you help? Thanks!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Frunning-shortcode-in-html-field%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15895574)
 * Hi [@filipnarcis](https://wordpress.org/support/users/filipnarcis/)
 * Sorry to hear you are having this issue.
 * Can you verify if your form is loading from Ajax on Form > Behaviour > Rendering
   mode?
 * When the form loads from Ajax the DOM will load the JS before the form renders,
   so in case the script is looking for the tags it wouldn’t work as tags don’t 
   exist yet, so disabling the Ajax method can help.
 * Let us know the result you got.
    Best Regards Patrick Freitas
 *  Thread Starter [narcisF](https://wordpress.org/support/users/filipnarcis/)
 * (@filipnarcis)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15896176)
 * Thank you for your response.
    Rendering mode was already unchecked using ajax.
   If I choose ajax the shortcode appears as shortcode format, it’s not rendering
   at all. The problem seems to be elsewhere.
 *  Thread Starter [narcisF](https://wordpress.org/support/users/filipnarcis/)
 * (@filipnarcis)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15896181)
 * I also tried this code but it’s not working:
 *     ```
       // Render shortcode on HTML fields
       add_filter( 'forminator_replace_variables', 'do_shortcode' );
       // Include shortcode output to hidden field
       add_filter( 'forminator_form_submit_field_data', function( $field_data_array ){
   
           $form = array(
               'field' => 'html-12', // Form html field
               'shortcode' => '[table id=1 /]' // 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;
   
       });
       ```
   
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15897653)
 * Hi [@filipnarcis](https://wordpress.org/support/users/filipnarcis/)
 * In this snippet that you tested, only this one line is relevant to the case:
 * `add_filter( 'forminator_replace_variables', 'do_shortcode' );`
 * However, I don’t think it’s a matter of “shortcode execution”. It is execucted
   correctly as you can already see the table in the field. The shortcode output
   itself doesn’t include any JS scripts to handle table behavior.
 * JS is included in the page footer and it seems for some reason it’s not able 
   to “find” relevant elements in DOM and that’d be more of Tablepress issue rather
   than Forminator.
 * However, the HTML field is not store in form submission and e-mail notification
   and it doesn’t “interact” with other fields – it’s purely informational. Even
   if this would work, it would only display it and that’s it.
 * Is there any specific reason for putting the table there rather than just including
   it on page right below the form?
 * Kind regards,
    Adam
 *  Thread Starter [narcisF](https://wordpress.org/support/users/filipnarcis/)
 * (@filipnarcis)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15897699)
 * I want to display it that way because in this form (wich is not finished) will
   be almost 40 tables and they will appear one by one as the user slects a field(
   with rules) so they can identify some data in that tables for selecting the next
   one. That’s why i need it to be in the form. In this case means I have to find
   a workaround.
    Thank you for your answear.
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15898201)
 * Hi [@filipnarcis](https://wordpress.org/support/users/filipnarcis/)
 * Thank you for response!
 * This makes sense and I understand why you want to use it that way. However, I
   did some more testing and I’m afraid I don’t see a workaround here.
 * There are two main issues:
 * 1. JS not working in the first place
 * As mentioned previously, it’s not really a matter of shortcode being processed
   correctly or not. If the table is showing up, shortcode is working. The problem
   is that the JS is not correctly handling the DOM and upon further checkup it 
   turns out it’s directly related to the DataTables library. It’s actually a 3rd-
   party library used by Tablepress plugin (not even from Tablepress developers).
 * There seems to be no any obvious conflicts or errors with Forminator and there
   doesn’t seem to be anything on Forminator end that should/could be fixed. It 
   requires some changes in either how DataTables library is initialized (by the
   TablePress plugin) or how it handles tables.
 * 2. Conditional visibility
 * You mentioned that tables should be showing up when adding select fields. This
   is yet another issue because even if these tables start to work in current configuration,
   then making more HTML fields to show up on site conditionally means a lot of 
   additional JS and dynamically handled (by JS) fields on front. This would cause
   further conflicts.
 * To sum it up, making it all work together would require a lot of complex custom
   development which is out of the scope of this forum (note that using anything
   JS-driven inside Forminator forms is a custom feature and not bug fixing as Forminator
   is not designed to handle this kind of input).
 * A workaround could be to use “static” tables. A 36 or so rows table isn’t super-
   long in my opinion so if you disable DataTables functions in table settings (
   when you edit table you can do so at the bottom of table settings) a full table
   should be showing up and while there’d be no paging and sorting, it would be 
   displayed and those tables should work fine with conditionally visible HTML fields.
 * Kind regards,
    Adam
 *  Thread Starter [narcisF](https://wordpress.org/support/users/filipnarcis/)
 * (@filipnarcis)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15898231)
 * Good idea to use static tables with all rows. It’s just a little more scrolling.
   it should be no problem. Thank you for your answer and testing. 🙂 Good plugin
   support for Forminator!

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

The topic ‘running shortcode in html field’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 7 replies
 * 3 participants
 * Last reply from: [narcisF](https://wordpress.org/support/users/filipnarcis/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/running-shortcode-in-html-field/#post-15898231)
 * Status: resolved