Halo Esports Wiki

We are currently performing extensive maintenance to this wiki and as a result there will likely be errors. Please be patient while we work to fix all problems.

READ MORE

Halo Esports Wiki
Advertisement

To edit the documentation or categories for this module, click here.


-- FormUtil
local forms = {}

-- if you have an ordered list of fields and an ordered list of values
function forms.makeBaseQueryURL(form, template, fields, values)
	local tbl = {}
	for k, v in ipairs(fields) do
		tbl[#tbl+1] = template .. '%5B' .. v .. '%5D=' .. values[k]
	end
	
	partialurl = string.format('https://lol.gamepedia.com/Special:RunQuery/%s?%s',
		form,
		string.gsub(table.concat(tbl,'&'),' ','%%20')
		)
		
	url = partialurl .. '&pfRunQueryFormName=' .. form
		
	return { full = url, partial = partialurl }
end

-- if you don't care about order and just want to make a query from all args
function forms.makeBaseQueryURLFromArgs(form, template, args)
	local tbl = {}
	for k, v in pairs(args) do
		if v ~= 'No' then
			tbl[#tbl+1] = template .. '%5B' .. k .. '%5D=' .. v
		end
	end
	
	partialurl = string.format('https://lol.gamepedia.com/Special:RunQuery/%s?%s',
		form,
		string.gsub(table.concat(tbl,'&'),' ','%%20')
		)
		
	url = partialurl .. '&pfRunQueryFormName=' .. form
		
	return { full = url, partial = partialurl }
end

-- if you have a partial query and an ordered list of fields and values to add to it at the end (this requires 2 separate lists of what to add)
function forms.addToQueryURL(form, template, oldquery, newfields, newvalues)
	
	local tbl = {}
	for k, v in ipairs(newfields) do
		tbl[#tbl+1] = template .. '%5B' .. v .. '%5D=' .. newvalues[k]
	end
	
	partialurl = oldquery .. '&' .. string.gsub(table.concat(tbl,'&'),' ','%%20')
		
	url = partialurl .. '&pfRunQueryFormName=' .. form
		
	return { full = url, partial = partialurl }
	
	
end

return forms
Advertisement