Chapter8 Syntax question

6 messages Options
Embed this post
Permalink
npm

Chapter8 Syntax question

Reply Threaded More More options
Print post
Permalink
In chapter 8 there's a line of code that looks like this:

<?=$form->button('UploadText',array('onClick'=>'$(\'#postAddForm
\').ajaxSubmit({target: \'#postTextUpload\',url:\"'.$html->url('/posts/text').'\
'});return false;'));?>

What purpose do the # (pound signs) serve?
davidgolding

Re: Chapter8 Syntax question

Reply Threaded More More options
Print post
Permalink
This is because of jQuery. In jQuery, $('#id') is short for the JavaScript call

document.getElementById('id')

Using the # symbol means the ID attribute, like in CSS; using the . symbol would reference a class attribute. Here, I've given the form id="postAddForm" so, in jQuery, we must use $('#postAddForm') to update it, etc.
--Dave

Author, "Beginning CakePHP: From Novice to Professional"

[ get your copy at: http://www.amazon.com/Beginning-CakePHP-Novice-Professional/dp/1430209771/ ]
Michelle

Re: Chapter8 Syntax question

Reply Threaded More More options
Print post
Permalink
I can't show you here, but in the above code all the ' and " are being echoed as HTML entities. IE amp#039;
davidgolding

Re: Chapter8 Syntax question

Reply Threaded More More options
Print post
Permalink
Are you copying/pasting from this web page? That would be your problem. Try manually typing it so the chars don't get affected by IE.
--Dave

Author, "Beginning CakePHP: From Novice to Professional"

[ get your copy at: http://www.amazon.com/Beginning-CakePHP-Novice-Professional/dp/1430209771/ ]
Michelle

Re: Chapter8 Syntax question

Reply Threaded More More options
Print post
Permalink
No...didn't copy and paste from here. Came here to see if I could find a solution. :)

This is my code:
<?php echo $form->button('UploadText',array('onClick'=>'$(\'#postAddForm\').ajaxSubmit({target: \'#postTextUpload\',url:\"'.$html->url('/posts/text').'\'});return false;'));?>

And the HTML output:

<input type="button" value="UploadText" onClick="$(amp#039;#postAddFormamp#039;).ajaxSubmit({target: amp#039;#postTextUploadamp#039;,url:\ampquot;/blog/posts/textamp#039;});return false;" />

I've replaced the & with amp so they won't be converted when I post and you can see what I mean. I'm using the latest stable version of CakePHP 1.2.1.8004 and so far haven't figured out what's changed.
Michelle

Re: Chapter8 Syntax question

Reply Threaded More More options
Print post
Permalink
In reply to this post by davidgolding
Fixed by adding 'escape' =>false to the array:

<?php echo $form->button('UploadText',array('onClick'=>'$(\'#postAddForm\').ajaxSubmit({target: \'#postTextUpload\',url:"'.$html->url('/posts/text').'\'});return false;','escape' =>false));?>