Fix the new field entry for field_order and required fields.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 24 Jul 2018 19:24:55 +0000 (15:24 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 24 Jul 2018 19:24:55 +0000 (15:24 -0400)
Setup required fields on the add edit forms.

models/admin/management/fields.php
views/admin/management/fields.html

index 93dd529..1268950 100644 (file)
@@ -270,7 +270,37 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
                 break;
 
             case 'addNew':
-                $this->insertEntry();
+                $gid          = filter_var( $_REQUEST['gid'], FILTER_VALIDATE_INT );
+                $field_name   = filter_var( $_REQUEST['field_name'] );
+                $field_type   = filter_var( $_REQUEST['field_type'] );
+                $admin_search = filter_var( $_REQUEST['admin_search'], FILTER_VALIDATE_BOOLEAN );
+                $required     = filter_var( $_REQUEST['required'], FILTER_VALIDATE_BOOLEAN );
+                $field_order  = 0;
+                if ( $gid ) {
+                    $field_order = $this->wpdb->get_var(
+                        "SELECT max(field_order)
+                           FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+                          WHERE uid = '" . GLM_MEMBERS_CONTACTS_PLUGIN_SLUG . "'
+                            AND gid = $gid"
+                    );
+                    $field_order++;
+
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_fields',
+                        array(
+                            'gid'          => $gid,
+                            'uid'          => $uid,
+                            'field_name'   => $field_name,
+                            'field_type'   => $field_type,
+                            'field_order'  => $field_order,
+                            'admin_search' => $admin_search,
+                            'required'     => $required,
+                        )
+                    );
+                    // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
+                    // $this->insertEntry();
+                }
                 break;
 
             case 'update':
index 54baaca..66e07f6 100644 (file)
@@ -12,7 +12,7 @@
         <table class="glm-admin-table">
             <tr>
                 <th class="glm-required">Group Name:</th>
-                <td><input id="groupName" type="text" name="group_name" class="glm-form-text-input"></td>
+                <td><input id="groupName" type="text" name="group_name" class="glm-form-text-input" required></td>
             </tr>
             <tr>
                 <th>Publish to Front End</th>
@@ -40,7 +40,7 @@
         <table class="glm-admin-table">
             <tr>
                 <th class="glm-required">Option Name:</th>
-                <td><input id="optionName" type="text" name="option_text" class="glm-form-text-input"></td>
+                <td><input id="optionName" type="text" name="option_text" class="glm-form-text-input" required></td>
             </tr>
             <tr>
                 <th>Selected by Default</th>
             <tr>
                 <th class="glm-required">Field Name:</th>
                 <td>
-                    <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
+                    <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input" required>
                 </td>
             </tr>
             <tr>
                 <th class="glm-required">Field Type:</th>
                 <td>
-                    <select id="editFieldType" name="field_type">
+                    <select id="editFieldType" name="field_type" required>
                         {foreach $field_types as $val => $label}
                         <option value="{$val}">{$label}</option>
                         {/foreach}