1

I'm using the sweet alert plugin for fancy javascript alerts. But U only need one alert, when there is something in the $_GET var. No Problem. Then I had put in a facebook box into the "text" and the script was broken. I figured out that without the php if statement it works so the problem has to be the ' and " of the line:

echo 'text: "Thank you so much for your support!<br><br><small>
Now please follow us on Facebook.</small><br><br><div class="fb-follow" 
data-href0="https://www.facebook.com/pages/Juuin/1618729241739708" 
data-layout="box_count" data-show-faces="true"></div>",';` 

The whole script is looking like this:

    <?php
if($_GET['reg'] == "sucess"){
    echo '<script>';
    echo 'sweetAlert({';
    echo 'title: "You did it!",'; 
    echo 'text: "Thank you so much for your support!<br><br><small>Now please follow us on Facebook.</small><br><br><div class="fb-follow" data-href0="https://www.facebook.com/pages/Juuin/1618729241739708" data-layout="box_count" data-show-faces="true"></div>",'; 
    echo 'html: true';
    echo '});';
    echo '</script>';
}
   ?>
NightShadeQueen
  • 3,284
  • 3
  • 24
  • 37
Fabrizio
  • 69
  • 1
  • 8
  • This is erring in PHP? What is the error? – chris85 Sep 01 '15 at 05:47
  • Consider using a HERE DOC (eg. http://stackoverflow.com/questions/5673269) or a proper code-view separation framework.. – user2864740 Sep 01 '15 at 05:48
  • @chris85 there is no php Error, but something is missformated so the javascript won't get executed. – Fabrizio Sep 01 '15 at 05:55
  • @user2864740 thanks. will try the HERE DOC. – Fabrizio Sep 01 '15 at 05:55
  • i did it with heredoc. Same Result, no alert appears. – Fabrizio Sep 01 '15 at 06:24
  • I don't know JS well enough to resolve that without knowing the error. If you open console is there an error being reported? `reg` is set to `sucess`, or `success`? – chris85 Sep 01 '15 at 12:38
  • the if statement works good, and the script works good to, so long it's not in the if clause. I got an js error: SyntaxError: missing } after property list You can watch it live if you want: juuin.com/index.php?reg=sucess – Fabrizio Sep 01 '15 at 13:06
  • solved the problem. changed the ' and the " in the right directions. – Fabrizio Sep 01 '15 at 14:17

1 Answers1

0

Try this

<?php
if($_GET['reg'] == "sucess"){
   echo '<script> sweetAlert({title: "You did it!",text: "Thank you so much for your support!<br><br><small>Now please follow us on Facebook.</small><br><br><div class="fb-follow" data-href0="https://www.facebook.com/pages/Juuin/1618729241739708" data-layout="box_count" data-show-faces="true"></div>", html: true }); </script>';
}
   ?>

Let me know if it is helpful

Rajesh kannan
  • 624
  • 3
  • 16