Sandeep Tiwari Posted October 8, 2014 Share Posted October 8, 2014 Hello everyone , I need add to cart button inside cms pages of prestashop. I search a lot and one prestashop forum post recomended me to use this method : <p><a onclick="ajaxCart.add(product_id=2, attribute_id=0, true, null, quantity=1, null);">Add to cart</a> But after saving the page it becomes : <a>Add to cart</a> is left. Onclick function is removed after save. Please help . Its urgent. Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2014 Share Posted October 8, 2014 what ps version you use? 1 Link to comment Share on other sites More sharing options...
Sandeep Tiwari Posted October 8, 2014 Author Share Posted October 8, 2014 1.5.6.0 Version of Prestashop... Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2014 Share Posted October 8, 2014 okay in this case it's necessary to extend tinymce editor in your shop. it's because by default tinymce removes some kind of scripts and validation class doesnt accept js scripts in fields that use 'isHtml' validation method more information about extending tinymce for prestashop 1.5 you can find here: extend tinymce editor in prestashop 1.5 1 Link to comment Share on other sites More sharing options...
Sandeep Tiwari Posted October 8, 2014 Author Share Posted October 8, 2014 Thanks Vekia , I just found your post on google where you replied to replace your code with current one in class/Validate function isCleanhtml . I do that and it works . Thank you so much again. Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2014 Share Posted October 8, 2014 great! i marked topic title as solved. with regards, Milos 1 Link to comment Share on other sites More sharing options...
Deepak Palreddy Posted October 8, 2014 Share Posted October 8, 2014 Thank you for reply, I have followed the above link and made changes you suggested. Script is not getting modified in cms page. And product is not getting added to cart.. Link to comment Share on other sites More sharing options...
Sandeep Tiwari Posted October 8, 2014 Author Share Posted October 8, 2014 Hi Deepak Would you please go to class/Validate.php and find out the function : public static function iscleanhtml and comment the following bold lines : public static function isCleanHtml($html, $allow_iframe = false) { $events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange'; $events .= '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend'; $events .= '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove'; $events .= '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel'; $events .= '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart'; $events .= '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange'; $events .= '|onselectstart|onstart|onstop'; //if (preg_match('/<[\s]script/ims', $html) || preg_match('/('.$events.')[\s]=/ims', $html) || preg_match('/.*script\:/ims', $html)) //return false; //if (!$allow_iframe && preg_match('/<[\s]*(i?frame|form|input|embed|object)/ims', $html)) //return false; return true; } Link to comment Share on other sites More sharing options...
shaun_imakr Posted October 13, 2014 Share Posted October 13, 2014 I did that and it doesn't work. The editor still strips onclick piece of code when I save the page. Link to comment Share on other sites More sharing options...
Sandeep Tiwari Posted October 13, 2014 Author Share Posted October 13, 2014 Which version you are using .. you must go to validate.php under classes folder. please write down your code here .. Link to comment Share on other sites More sharing options...
Deepak Palreddy Posted October 13, 2014 Share Posted October 13, 2014 Hello, You need extend tinymce editor in your prestashop shop. Because by default tinymce removes some kind of scripts and validation class doesn't accept JS scripts in fields that use 'isHtml' validation. Follow the below links to extend tinemce... http://mypresta.eu/en/art/know-how/tinymce-editor-full-options-all-html-tags.html http://mypresta.eu/en/art/prestashop-16/extended-rich-text-editor.html Link to comment Share on other sites More sharing options...
shaun_imakr Posted October 13, 2014 Share Posted October 13, 2014 (edited) It's Prestashop 1.6.0.9 and the code looks like this: public static function isCleanHtml($html, $allow_iframe = false) { $events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange'; $events .= '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend'; $events .= '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove'; $events .= '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel'; $events .= '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart'; $events .= '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange'; $events .= '|onselectstart|onstart|onstop'; /* if (preg_match('/<[\s]*script/ims', $html) || preg_match('/('.$events.')[\s]*=/ims', $html) || preg_match('/.*script\:/ims', $html)) return false; if (!$allow_iframe && preg_match('/<[\s]*(i?frame|form|input|embed|object)/ims', $html)) return false; */ return true; } I disabled that validation before because I had to use javascripts on couple of pages (mostly for redirection) and for embedding of YouTube videos. But for some reason it turns <p><a onclick="ajaxCart.add(product_id=125, attribute_id=0, true, null, quantity=1, null);">Add to cart</a></p> to this: <p><a>Add to cart</a></p> Anyway, I sorted that out other way by adding the class for that link <a class="nameoftheclass">Add to Cart</a> and then in js/tools.js I added this: $(document).ready(function(){ $('.nameoftheclass').click(function(){ajaxCart.add(product_id=125, attribute_id=0, true, null, quantity=1, null);}); }); And it's working fine now Edited October 13, 2014 by shaun_imakr (see edit history) 1 Link to comment Share on other sites More sharing options...
Sandeep Tiwari Posted October 13, 2014 Author Share Posted October 13, 2014 Cheers .. Link to comment Share on other sites More sharing options...
Recommended Posts