I have a form that calls a success message with this code:
// Form processed successfully, return the success message
$result = array(
'type' => 'success',
'data' =>
$form->replacePlaceholderValues($successMessage)
);
the variable $successMessage is called if the form is successfully sent.
$successMessage = '<div class="success-message">Your message has been sent, thank you.</div>';
I want to process this Javascript popup rather than the success message using this code
<script>
$(document).ready(function(){
$().socialTrafficPop({
timeout: 999,
title: "One Great Site!",
message: '<div class="success-message">Your message has been sent, thank you.</div><em>Share Send Email Free</em>!',
google_url: "http://tyler.tc/",
fb_url: "somesite.com",
closeable: true,
advancedClose: false,
opacity: '0.45',
twitter_method: "tweet",
tweet_url: 'somesite.com',
tweet_text: 'Just tried out this awesome plugin Social Traffic Pop - Its Amazing!'
});
});
</script>
Can I call it from the variable $successMessage? Or is there a better and more appropriate way to call this script? How would I do either?
Also, I put the necessary scripts inside of the header.php file which gets called by the index.php file which projects the homepage. Is there somewhere else I should be putting the necessary scripts that the popup code needs to function rather than header.php?
I have tried endlessly around the code below and it doesn't seem to work. The $successMessage works without the JavaScript fine, but when I try to add the JavaScript the form will not process anymore. Here is one of the many things I have tried. Thank you for any help.
<?php
$successMessage = echo "
<script>
$(document).ready(function(){
$().socialTrafficPop({
timeout: 999,
title: "One Great Site",
message: '<div class="success-message">Your message has been sent, thank you.</div><em>Share Send Email Free</em>!',
google_url: "http://tyler.tc/",
fb_url: "someurl.com",
closeable: true,
advancedClose: false,
opacity: '0.45',
twitter_method: "tweet",
tweet_url: 'someurl.com',
tweet_text: 'Just tried out this awesome!'
});
});
</script>";
"in PHP and Javascript in thescriptblock you're trying toecho(and I doubt you need the$successMessagevariable). You need to either escape the"(like so:\") within the Javascript, or use'instead. Note, if you look at the code highlighting above, you'll notice that thescripttag text is alternately red and highlighted in different colors. This is an indicator of a problem.heredoc.ob_start()may also be a solution