added testing to ensure category edit field isn't blank before editing db
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 3 Mar 2016 18:35:50 +0000 (13:35 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 3 Mar 2016 18:35:50 +0000 (13:35 -0500)
models/admin/events/categories.php
views/admin/events/categories.html

index 9182b7e..429b72e 100644 (file)
@@ -123,39 +123,52 @@ class GlmMembersAdmin_events_categories  extends GlmDataEventsCategories
                     }
             }
         }
+        // checking if the save action is performed to save an edited name field
         if($_REQUEST['save'] == 'save'){
             $catField = array_filter($_REQUEST, function($k) {
-            return preg_match('/^cat/',$k);
-        }, ARRAY_FILTER_USE_KEY);
-        
+                return preg_match('/^cat/',$k);
+            }, ARRAY_FILTER_USE_KEY);
+            if(isset($catField)){
+                echo "asdf";
+            }
             foreach($catField as $cat){
                 $title = trim(filter_var($cat,FILTER_SANITIZE_STRING));
             }
           
             $table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX;
+            
              // get ID of selected category
-                   $sql = "SELECT id
-                            FROM ". GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "categories
-                            WHERE name = " . "'$title'". "
-                            ;";
+             $sql = "SELECT id
+                     FROM ". GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "categories
+                     WHERE name = " . "'$title'". "
+                     ;";
                  
                    $id = $this->wpdb->get_results($sql, ARRAY_A);
+                   
                    foreach($id[0] as $key=>$value){
                        $id = $value;
                    } 
-                $editField = array_filter($_REQUEST, function($k) {
-            return preg_match('/^edit/',$k);
-        }, ARRAY_FILTER_USE_KEY);
-        foreach($editField as $edit){
+              
+                    $editField = array_filter($_REQUEST, function($k) {
+                        return preg_match('/^edit/',$k);
+                    }, ARRAY_FILTER_USE_KEY);
+                
+            
+            foreach($editField as $edit){
                 $editTitle = trim(filter_var($edit,FILTER_SANITIZE_STRING));
             }
-                $sql2 = "UPDATE " . "$table" . "categories
-                    SET name = " .  "'$editTitle'" . "    
-                    WHERE id = " . $id . "
-                    ;";  
+            // run sql statement only if the edit field isn't blank
+            if($editTitle != ''){
+                 // edit category name
+                 $sql2 = "UPDATE " . "$table" . "categories
+                 SET name = " .  "'$editTitle'" . "    
+                 WHERE id = " . $id . "
+                 ;";  
              $this->wpdb->query($sql2);
+            }  
+            
         }
-
+        
         // retrieve category names
         $entries = $Categories->getList();
         foreach($entries as $keys=>$value){
@@ -167,7 +180,17 @@ class GlmMembersAdmin_events_categories  extends GlmDataEventsCategories
             $names[] = $entries[$id]['name'];
         }
     
-//         echo '<pre>', print_r($names, true), '</pre>';
+        // Delete a category entry //////////////////////////////
+        if($_REQUEST['delete'] == 'delete'){
+            echo "test";
+
+        }
+        
+        
+        
+        
+        
+        
          // Compile template data
         $templateData = array(
             'displayData' => $displayData,
index 95cea9b..a088b32 100644 (file)
@@ -25,7 +25,7 @@
                 <tr>                           
                     <td><input readonly name='catListField{$val}' class="catField" value="{$category}"><input class="edit" type="text" id="edit{$val}" name="edit{$val}"></td>
                     <td><input class="button glm-button" onclick="form{$val}.submit();" type="button" value="Save"><input type="hidden" name="save" value="save"></td>
-                    <td><input class="button glm-button submit" type="submit" value="Delete"></td>
+                    <td><input class="button glm-button submit" type="button" value="Delete "><input type="hidden" name="delete" value="delete"></td>
                 </tr>
             </table>          
         </form>