-1

I'm using a script to create a popup button. The message that appears in the popup comes from a JavaScript file. Part of that includes a WordPress shortcode to display a form from Caldera Forms, although this could really be any form and any shortcode. My script currently looks like this:

bioEp.init({
    html: '<div id="bio_ep_content">' +
    '<h2>Contact Form</h2>' +
    '<p>Submit your contact details here.</p>' +
'<?php echo do_shortcode("[caldera_form id="CF5b425517a3263"]"); ?>' +
'</div>',
css: '#bio_ep {width: 65%; max-width: 800px; height: auto; background-color: #fff; text-align: center; padding: 25px}',
delay: 1,
cookieExp: 0

});

It's all good except the form doesn't appear. The shortcode appears like a comment. Like this:

<!--?php echo do_shortcode("[caldera_form id="CF5b425517a3263"]"); ?-->

Is there someway to make the shortcode work within this JavaScript?

Adam Bell
  • 1,049
  • 1
  • 16
  • 50
  • 2
    http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – Teemu Jul 08 '18 at 18:45
  • 1
    PHP has already finished executing by the time it gets to the client to run a script. This isn't going to work. – Devon Bessemer Jul 08 '18 at 18:46
  • @Devon that doesn't explain, why it is commented. This seems weird to me. Edit: Looked it up, it's default browser behavior to comment unknown code. And the browser doesn't know php, so comment. – dscham Jul 08 '18 at 18:50

1 Answers1

0

As Teemu's comment suggests. What you wrote is trying to run PHP code in the browser.

You'll have to come up with another way to dynamically import that shortcode if you really need that.

dscham
  • 547
  • 2
  • 10
  • Yea, but I have no idea how to execute that. Thus, why I'm asking the question here. Because I'm sure I can't be the only one with this problem. – Adam Bell Jul 08 '18 at 21:53
  • sounds like either if you want to use a shortcode (which has to run inside a wp post) you need to 'pop-up' (if it has to be a pop-up) another wordspress page or post with a simplified template. Alternatively you could just link, opening in a new window to the post/page with the shortcode in it. – anmari Jul 09 '18 at 02:08