0

I am working with wordpress and I am trying to get this form to appear when you press a button

<div class="head">
    <p><?php echo __('Tests pabeigts, lūdzu iesniedziet testu'); ?></p>
</div>

<script>
    function do()
    {
        <?php echo do_shortcode( '[wpforms id="1995"]' ); ?>
    }
</script>

<div class="content">
    <button onclick="do()" class="btn btn-blue" type="submit">
        <?php echo __('Iesniegt'); ?>
    </button>
</div>

The function do() is supposed to make a form appear after you press the Submit button, but it just returns results and I cant figure out why.

treyBake
  • 6,440
  • 6
  • 26
  • 57
janispanis
  • 11
  • 3
  • 3
    2 things, 1) you should never ever mix PHP and JS together. They're executed differently and thus, can cause unexpected behaviour and 2) don't use inline-js, it's hard to maintain :) much better to use eventHandler's :) – treyBake Jul 24 '19 at 08:56
  • 2
    To add to the above comment, you should start with checking the source code of your page, that probably does not look like you expect it to. – jeroen Jul 24 '19 at 08:56

1 Answers1

0

Basically, you cannot display the shortcode in javascript code, for that you will need to add the form in particular div by default hidden

<div class="wp_form_section" style="display:none;">
<?php echo do_shortcode([wpforms id="1995"]); ?>
</div>

and then you will need to display the div onclick action

<script>
    function do()
    {
        jQuery('.wp_form_section').show();
    }
</script>

This might be work for you.

Pixlogix
  • 621
  • 4
  • 7