From 8e42e7ed45c756dcbd470ac4b940a0203a357f7c Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 26 Oct 2017 11:44:21 -0400 Subject: [PATCH] adding fieldfail array that is merged in with the custom fields data using a custom field fail array merged in with the custom fields data to add field fail styles in the view if a required field is empty --- classes/customFieldPluginSupport.php | 11 +++++-- css/admin.css | 6 ++-- models/admin/entity/fields.php | 3 +- views/admin/entity/fields.html | 45 +++++++++++++++++----------- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/classes/customFieldPluginSupport.php b/classes/customFieldPluginSupport.php index e974327..e43bf7a 100644 --- a/classes/customFieldPluginSupport.php +++ b/classes/customFieldPluginSupport.php @@ -16,7 +16,7 @@ */ function customFieldsSaveFields( $entityID ){ global $wpdb; - echo $entityID; + $fieldFail = array(); // If no data for custom field then return if ( !isset( $_REQUEST['glm_custom_field'] ) ) { return false; @@ -40,13 +40,18 @@ function customFieldsSaveFields( $entityID ){ } } foreach($_REQUEST['glm_custom_field'] as $fieldID =>$fieldValue){ + $cfData[$fieldID] = $fieldValue; if( in_array( $fieldID,$requiredFields )){ if($fieldValue === ''){ - return $_REQUEST['glm_custom_field']; + $fieldFail['fieldFail'][$fieldID] = true; } } } - + + if(!empty($fieldFail)){ + $fieldFailData = $cfData + $fieldFail; + return $fieldFailData; + } // Loop through the glm_custom_field array foreach ( $_REQUEST['glm_custom_field'] as $fieldId => $fieldValue ) { $fieldData =array( diff --git a/css/admin.css b/css/admin.css index 2614375..cdd8308 100644 --- a/css/admin.css +++ b/css/admin.css @@ -5,10 +5,12 @@ font-weight: bold; line-height: 1; } - +.glm-admin-custom-fields .glm-input-wrapper{ + display: inline-block; +} @media(min-width: 1024px){ .glm-admin-custom-fields input[type=text]{ - width: 50%; +/* width: 50%;*/ } } @media(max-width: 1024px){ diff --git a/models/admin/entity/fields.php b/models/admin/entity/fields.php index f5feabe..dd77474 100644 --- a/models/admin/entity/fields.php +++ b/models/admin/entity/fields.php @@ -137,8 +137,9 @@ class GlmMembersAdmin_entity_fields extends GlmDataFieldsCustomFields $entityID = $actionData['entityID']; $uid = $actionData['uid']; $fieldFail = $actionData['cfData']; +// print_r($fieldFail); } - + switch ($option) { default: diff --git a/views/admin/entity/fields.html b/views/admin/entity/fields.html index 456ba6f..a00af22 100644 --- a/views/admin/entity/fields.html +++ b/views/admin/entity/fields.html @@ -3,24 +3,33 @@
{$field.field_name}
- {if $field.field_type.name == 'text'} - - - {elseif $field.field_type.name == 'textarea'} - {php} - wp_editor('{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape:quotes}{/if}', 'custom-field-{$field.id}', array( - 'media_buttons' => false, - // 'quicktags' => false, - // 'wpautop' => false, NOTE: Dont's use. Problem when numerous spaces before text. - 'textarea_name' => '{$prefix}[{$field.id}]', - 'editor_height' => 200, // Height in px, overrides editor_rows - // 'textarea_rows' => 8 - )); - {/php} - {elseif $field.field_type.name == 'checkbox'} - - - {/if} + + {$fail = ''} + {if array_key_exists('fieldFail', $customFieldsData)} + {if array_key_exists($field.id,$customFieldsData['fieldFail'])} + {$fail = 'glm-form-bad-input'} + {/if} + {/if} +
+ {if $field.field_type.name == 'text'} + + + {elseif $field.field_type.name == 'textarea'} + {php} + wp_editor('{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]|escape:quotes}{/if}', 'custom-field-{$field.id}', array( + 'media_buttons' => false, + // 'quicktags' => false, + // 'wpautop' => false, NOTE: Dont's use. Problem when numerous spaces before text. + 'textarea_name' => '{$prefix}[{$field.id}]', + 'editor_height' => 200, // Height in px, overrides editor_rows + // 'textarea_rows' => 8 + )); + {/php} + {elseif $field.field_type.name == 'checkbox'} + + + {/if} +
{/foreach} -- 2.17.1