![]() |
Color and Size Filter - 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: Color and Size Filter (/showthread.php?tid=70362) |
Color and Size Filter - msz900 - 03-30-2018 Hi I searched a lot for my issues, but did not find what I want, I also Posted a Question on stackOverflow but did not get the response and then I just got here and hope may be someone have the same issue in past or have some sort of code which will help me to fix my issue. I have a filter section, where user can filter product by Size, Color etc. I somehow did the filter code but now I am stuck in the ajax issue. Issue is that When color or size checkbox is empty then it throw error of foreach loop Code: [color=#6c6c6c][size=small][font=Arial, sans-serif]Severity: Warning[/font][/size][/color] I know the error is because of empty data in variable. There is also an issue in my query. The filter result is not 100% correct and I say that because I did Code: [code]var_dump($query) . I also need to control the empty or null section, like if the checkbox is unchecked then it will not send / post the value to the controller... My Ajax Code Code: var selected = new Array(); My view code Code: <!-- Color --> My Controller Code PHP Code: function filt_color() My Model Code PHP Code: function cfilter($colors,$sizes) For graphical result please review the attach images / links. if the images will not show then these are the links: https://imgur.com/M03vwvm p_attributes table https://imgur.com/ivkKdez product table https://imgur.com/KiOw9FR Console result https://imgur.com/VqfGiEY Var_dump($query) result Please post your ideas / codes / helpful links anything you can, Please make sure to use the CI Active Records for queries, because I don’t want to do it in plain query. Any help will be highly appreciated. Thanks. [/code] RE: Color and Size Filter - InsiteFX - 03-31-2018 Check boxes and radio buttons have no setting at all if they are not checked. You need to first check to see if the check box or radio button is checked or empty before you do anything else in your code. PHP Code: if ( ! empty($this->input->post("checkBoxName"))) You could also us isset etc; The thing is you need to check to make sure it is checked. RE: Color and Size Filter - msz900 - 03-31-2018 (03-31-2018, 04:07 AM)InsiteFX Wrote: Check boxes and radio buttons have no setting at all if they are not checked. Yes I am doing that while posting data. But I don't know ho to validate / check Ajax Data variable for empty before posting. Like: Code: function clr(){ but I don't know how to get / validate it, like data.color.length<0 or data.color !=='' etc. RE: Color and Size Filter - InsiteFX - 04-01-2018 See this article JavaScript: Form Validation using Ajax RE: Color and Size Filter - msz900 - 04-01-2018 (04-01-2018, 04:15 AM)InsiteFX Wrote: See this article Did you check the var_dump screen shot? The query is also returning wrong result.. https://imgur.com/VqfGiEY |