Cart class doesn't accept product names with accented characters - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Cart class doesn't accept product names with accented characters (/showthread.php?tid=29501) |
Cart class doesn't accept product names with accented characters - El Forum - 04-12-2010 [eluser]mudshark[/eluser] Hi everyone, I'm currently developing an e-commerce site for a wine merchant. I'm using CI's cart class, which as you probably know has this syntax for adding items to the cart: Code: $data = array( This works fine for me - except when the name of the item is something along the lines of "Côtes du Rhône rouge 37.5 cl 2007", or "Crème d'Abricot". Obviously the accented characters are preventing insertion of the product to the cart. I've tried the following within the product's shopping cart form to "neutralize" the accented characters: Code: <?php echo form_hidden('name', ascii_to_entities($product_name)); ?> ... but even with that function in use, I cannot insert the item in the cart. Am I doing something wrong? How can I get this to work? Thanks for your help! :-) Cart class doesn't accept product names with accented characters - El Forum - 04-12-2010 [eluser]mudshark[/eluser] I've had a look at /libraries/Cart.php and saw this at the top: Code: var $product_name_rules = '\.\:\-_ a-z0-9'; ... so it's the regex that's preventing my accented product names from being added to the cart. How do I change this regex so that it will accept accents (ô, é, è, à, û, ç) and/or any characters that are produced by the ascii_to_entities() function (see Text Helper)? Cart class doesn't accept product names with accented characters - El Forum - 04-12-2010 [eluser]mudshark[/eluser] Right, well ended up commenting out this bit in Cart.php: Code: if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) That'll have to do until I find a proper regex... Cart class doesn't accept product names with accented characters - El Forum - 05-02-2010 [eluser]ontguy[/eluser] You could also extend the Cart library and add the characters you want allowed. Code: <?php if (!defined('BASEPATH')) exit('No direct access allowed.'); Cart class doesn't accept product names with accented characters - El Forum - 05-02-2010 [eluser]skunkbad[/eluser] I've had issues with this too, and use [:print:] in my regex, but just found that it won't allow pound signs "#", which I like. I think you just have to customize the regex to your liking, and learning regex is part of the fun. Cart class doesn't accept product names with accented characters - El Forum - 03-07-2012 [eluser]Unknown[/eluser] We used: Code: $this->ci->cart->product_name_rules = '^.'; Allows everything as a name. |