Ci 3 $_POST not accepting spaces? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Ci 3 $_POST not accepting spaces? (/showthread.php?tid=75426) |
Ci 3 $_POST not accepting spaces? - sanderv - 02-05-2020 Hi All, I am building a car dealer app for a friend using Ci 3 and HMVC. from the database i am querying a set of car options, that get listed in a view file as checkboxes. in the controller : PHP Code: function list_options(){ and displayed in a form like this : PHP Code: foreach ($caroptions as $key => $value) { so far so good, but when i actually select some of the checkboxes and submit the form , data gets collected like this : PHP Code: $data["optionsarray"] = $this->input->post('options[]', TRUE); Now, when the key contains spaces, this does not work and an empty key is returned. like ["0"] => string(1)"1" for example if i select an option called: 2 door , then the key will not be [2 door] but it will be empty. Same goes for when i use 2 words seperated by a space like " heated seats" if i use words that have no spaces like "ABS" or "airconditioning" then the key is set and will return ["ABS"]=> string(1) "1" When i recreate the above scenaria in plain PHP, it works without errors. i have no idea why this is not working in codeigniter? anyone any idea? RE: Ci 3 $_POST not accepting spaces? - jreklund - 02-05-2020 You will need to put your options in a quoted string. Or generate slugs that change spaces into hyphens (-). <input name="options['<?= $row ?>']" value ="1" type="checkbox"> RE: Ci 3 $_POST not accepting spaces? - sanderv - 02-05-2020 (02-05-2020, 11:04 AM)jreklund Wrote: You will need to put your options in a quoted string. Or generate slugs that change spaces into hyphens (-). I tried this, but it doenst work either. it returns : array(1) { [0]=> string(1) "1" }, even for the keys that have no spaces in them like the word "ABS" the only thing that seems to work is PHP Code: <input name="options[<?= $row ?>]" value ="1" type="checkbox"> and this only works if there is no space in the key. RE: Ci 3 $_POST not accepting spaces? - InsiteFX - 02-06-2020 If a checkbox is not checked then it has no value and is empty. RE: Ci 3 $_POST not accepting spaces? - jreklund - 02-06-2020 Personally I have never tried making an options array like that. I always put my value in value="" that I want to be added to the options array. PHP Code: <?php if( !empty($groups['department']) ): ?> And grabbing it like this, to retrieve the actual value. PHP Code: public function _get_documents_department() In case I want to have the name and ID i put value="key_value", and make an explode('_', $array); on the other end. If I for some reason don't want to use multiple names for different settings. |