Yii Framework Forum: PHP is trying to execute my javascript - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP is trying to execute my javascript Rate Topic: -----

#1 User is offline   JScott 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 106
  • Joined: 26-March 15

Posted 09 November 2016 - 12:17 PM

I am having an odd problem.

I have a chunk of javascript that I need to insert into my payment page view file.

But PHP is trying to execute it!!!????!!!


$stripescript2 = <<<JS2

    <script type="text/javascript">
    var $form = jQuery("#payment-form");
    $form.submit(function(event) {
        // Disable the submit button to prevent repeated clicks:
        $form.find(".submit").prop("disabled", true);

        // Request a token from Stripe:
        Stripe.card.createToken($form, stripeResponseHandler );

        // Prevent the form from being submitted:
        return false;
    });
    </script>
JS2;

$this->registerJs( $stripescript2 , \yii\web\VIEW::POS_READY);


Here is the PHP error....

PHP Notice – yii\base\ErrorException

Undefined variable: form
1. in /home/nginx/public/basic/views/checkout/checkout.php at line 101

</script>
JS1;
 
$this->registerJs( $stripescript1 , \yii\web\VIEW::POS_END);
 
$stripescript2 = <<<JS2
 
    <script type="text/javascript">
    var $form = jQuery("#payment-form");
    $form.submit(function(event) {                <<------------   ERROR ON THIS LINE
        // Disable the submit button to prevent repeated clicks:
        $form.find(".submit").prop("disabled", true);
 
        // Request a token from Stripe:
        Stripe.card.createToken($form, stripeResponseHandler );
 
        // Prevent the form from being submitted:
        return false;
    });


Thanks
-John
0

#2 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 09 November 2016 - 01:58 PM

You must escape "$" when using heredoc syntax:

var \$form = jQuery("#payment-form");

1

#3 User is offline   JScott 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 106
  • Joined: 26-March 15

Posted 09 November 2016 - 03:32 PM

AH HA!!!

That was it. I had not thought about needing to escape anything with HEREDOC.

I figured it was something simple I was missing.

Thanks
-John
0

#4 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 09 November 2016 - 03:44 PM

You should use some IDE or editor with syntax highlighting - it is pretty obvious then. :)
0

#5 User is offline   JScott 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 106
  • Joined: 26-March 15

Posted 09 November 2016 - 04:53 PM

Not with PHPStorm. It did not give me any clues....

Then again... It was not really an error. It was just not what I wanted.

PHP was trying to replace $form in the text, but $form was not defined anywhere...

-John


View Postrob006, on 09 November 2016 - 03:44 PM, said:

You should use some IDE or editor with syntax highlighting - it is pretty obvious then. :)

0

#6 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 09 November 2016 - 05:03 PM

View PostJScott, on 09 November 2016 - 04:53 PM, said:

Not with PHPStorm. It did not give me any clues....


That's odd. This is how it looks in NetBeans:

Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users