Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getSaveFields()
- {
- let $process_elements = jQuery('#admin_content input, #admin_content select');
- let response = {};
- $process_elements.each(function(index, element)
- {
- if(element.name == '')
- {
- return true;
- }
- let $element = jQuery(element);
- let element_val = jQuery.trim($element.val());
- if(element_val != '')
- {
- if(((element.type == 'checkbox' || element.type == 'radio') && $element.is(':checked')) || (element.type != 'checkbox' && element.type != 'radio') || element.nodeName == 'SELECT')
- {
- if(element.name.indexOf('[') != -1)
- {
- let names = element.name.split('[');
- //a main position exists alywas so we can directly assign it
- let main_position = names.shift();
- //a sub position exists too but we need to check if it has a name or not
- let sub_position = names.shift().replace(']', '').toString();
- //depending on the sub_position string we need to create an object or an array if the main is not set already
- if(typeof response[main_position] == 'undefined')
- {
- if(sub_position != '')
- {
- response[main_position] = {};
- }
- else
- {
- response[main_position] = [];
- }
- }
- if(sub_position == '')
- {
- response[main_position].push(element_val);
- }
- else
- {
- let sub_sub_position = undefined;
- if(names.length > 0)
- {
- sub_sub_position = names.shift().replace(']', '').toString();
- }
- if(typeof sub_sub_position == 'undefined')
- {
- response[main_position][sub_position] = element_val;
- }
- else
- {
- //only create the object/array if it is not defined
- if(typeof response[main_position][sub_position] == 'undefined')
- {
- if(sub_sub_position != '')
- {
- response[main_position][sub_position] = {};
- }
- else
- {
- response[main_position][sub_position] = [];
- }
- }
- if(sub_sub_position == '')
- {
- response[main_position][sub_position].push(element_val);
- }
- else
- {
- response[main_position][sub_position][sub_sub_position] = element_val;
- }
- }
- }
- }
- else
- {
- response[element.name] = element_val;
- }
- }
- }
- });
- return response;
- }
Add Comment
Please, Sign In to add comment