Looping through the request array
authorLaury GvR <laury@gaslightmedia.com>
Fri, 26 Feb 2016 17:19:34 +0000 (12:19 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 26 Feb 2016 17:19:34 +0000 (12:19 -0500)
models/admin/member/social.php
views/admin/member/social.html

index ce943c7..b13e242 100644 (file)
@@ -180,27 +180,46 @@ class GlmMembersAdmin_member_social extends GlmDataSocial
                 'baseurl' => 'www.photobucket.com'
             ),
         );
-        
+
         // If there's an action option
         if (isset($_REQUEST['option'])) {
             $option = trim(filter_var($_REQUEST['option'],FILTER_SANITIZE_STRING));
+        } else {
+            echo "FAIL option REQUEST";
         }
-        if (isset($_REQUEST['facebook'])) {
-            $facebookUrl = trim(filter_var($_REQUEST['facebook'],FILTER_SANITIZE_STRING));
+        if (isset($_REQUEST['socialname-facebook'])) {
+            $socialUrl = trim(filter_var($_REQUEST['socialname-facebook'],FILTER_SANITIZE_STRING));
+        } else {
+            echo "FAIL socialUrl REQUEST";
         }
-//      
-//        $option = $_REQUEST['option'];
-//        $testurl = $_REQUEST['facebook'];
-//        echo $option;
-//        echo 'test';
-//        echo $testurl;
-        $socialData = $this->editEntry($memberID);
-        
-        if (!$socialData) {
-            $socialData = $this->newEntry($memberID);
-            $newSocial = true;
-            
+        echo "<hr />Request:<table>";
+        foreach($_REQUEST as $key=>$value) {
+            echo("<tr><td>$key</td><td>$value</td></tr>");
+        }
+        echo "</table>";
+        $socialarray = array_filter($_REQUEST, function($k) {
+            return preg_match('/^socialname-/',$k);
+        }, ARRAY_FILTER_USE_KEY);
+        echo "<hr />SocialArray:<table>";
+        echo "<pre>";print_r($socialarray,true);echo "</pre>";
+        foreach($socialarray as $key=>$value) {
+            echo("<tr><td>$key</td><td>$value</td></tr>");
         }
+        echo "</table><hr />";
+        
+        
+
+        // this causes ALERT: Empty Fields List in data abstract buildFieldsList()! Likely programming error.
+        // $socialData = $this->editEntry($memberID);
+        
+//        if (!$socialData) {
+//            $socialData = $this->newEntry($memberID);
+//            $newSocial = true;
+//        }
+
+        
+        
+        
 //        switch($option) {
 //            case 'update':
 //            default:
@@ -234,9 +253,7 @@ class GlmMembersAdmin_member_social extends GlmDataSocial
 
 //        if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'submit') {
         if ($option == 'submit') {
-            
-            $socialUrl = "www.socialurl.com";
-
+          
             $socialData = $this->updateEntry($memberID);
 
             if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
@@ -247,22 +264,25 @@ class GlmMembersAdmin_member_social extends GlmDataSocial
 //            echo $memberID;
             // If update was successful then use editEntry() to setup for the edit again.
             if ($socialData) {
-
+                $social = 'facebook';
                 $socialData = $this->editEntry($memberID);
                 $socialUpdated = true;
 
                 // Also update all member info records with any possible name change
                   $sql = "
                 INSERT INTO ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."socialURL
-                   (member_id,facebook_url)
-                 VALUES (".$memberID.", '".$facebookUrl."')
+                   (member_id,".$social."_url)
+                 VALUES (".$memberID.", '".$socialUrl."')
             ;";
-//                $sql = "
-//                    UPDATE ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."socialURL
-//                       SET facebook_url = '".addslashes($socialData['fieldData']['name'])."'
-//                     WHERE member_id = $memberID
-//                ;";
+                echo "<div>".$sql."</div>";  
+                $sql2 = "
+                    UPDATE ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."socialURL
+                       SET ".$social."_url = '".$socialUrl."'
+                     WHERE member_id = $memberID
+                ;";
+                echo "<div>".$sql2."</div>";
                 $this->wpdb->query($sql);
+                $this->wpdb->query($sql2);
 
             }
         }
index 8afd3bf..667cdf7 100644 (file)
@@ -2,7 +2,6 @@
     
     <h3>Members Social Tab</h3>
     <p>{$displayData}</p>
-<table class="glm-admin-table">
     <div class="wrap">
     <div id="glm-admin-content-container">
         <h3>Social Model</h3>
                         {$socialItem.name}
                     </th>
                     <td>
-                        <input type="text" placeholder="{$socialItem.name} URL" name="{$socialItem.name|lower}" class="glm-form-text-input">
+                        <input type="text" placeholder="{$socialItem.name} URL" name="socialname-{$socialItem.name|lower}" class="glm-form-text-input">
                     </td>
                 </tr>
             {/foreach}
             </table>
-            <input type="submit" class="button glm-button submit" value="{if $memberInfoID && $memberInfo}Update member information{else}Add new member information{/if}">
+            <input type="submit" class="button glm-button submit" value="submit" name='submit'>
         </form>
     </div>
 </div>