diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-07-12 15:57:36 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-07-12 15:57:36 +0000 |
commit | 02082d03de31af25beed17cf3d61ca513ea6f885 (patch) | |
tree | 34d3b187c326cf737c0684cb0654163e4accdbfd /lib/controllerfunctions.lua | |
parent | 4522cd8af6efd114b79b48eeddfa9660cfb08716 (diff) | |
download | acf-core-02082d03de31af25beed17cf3d61ca513ea6f885.tar.bz2 acf-core-02082d03de31af25beed17cf3d61ca513ea6f885.tar.xz |
Fixed redirect_to_referrer with GET data. Moved handling of multi select from acf_www-controller to controllerfunctions. Fixed form ids containing '.'. Added new handle_clientdata function to controllerfunctions. Modified password-controller to use handle_clientdata for multi select to work.k
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1299 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/controllerfunctions.lua')
-rw-r--r-- | lib/controllerfunctions.lua | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua index ec62fee..5c3e559 100644 --- a/lib/controllerfunctions.lua +++ b/lib/controllerfunctions.lua @@ -1,25 +1,54 @@ module(..., package.seeall) +function handle_clientdata(form, clientdata) + form.errtxt = nil + for name,value in pairs(form.value) do + value.errtxt = nil + if name:find("%.") then + -- If the name has a '.' in it, haserl will interpret it as a table + local actualval = clientdata + for entry in name:gmatch("[^%.]+") do + if tonumber(entry) then + actualval = actualval[tonumber(entry)] + else + actualval = actualval[entry] + end + if not actualval then break end + end + clientdata[name] = actualval + end + if value.type == "boolean" then + value.value = (clientdata[name] ~= nil) + elseif value.type == "multi" then + -- FIXME this is because multi selects don't work in haserl + local oldtable = clientdata[name] or {} + -- Assume it's a sparse array, and remove blanks + local newtable={} + for x=1,table.maxn(oldtable) do + if oldtable[x] then + newtable[#newtable + 1] = oldtable[x] + end + end + value.value = newtable + elseif value.type == "list" then + value.value = {} + if clientdata[name] and clientdata[name] ~= "" then + for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do + table.insert(value.value, ip) + end + end + else + value.value = clientdata[name] or value.value + end + end +end + function handle_form(self, getFunction, setFunction, clientdata, option, label, descr, redirectOnSuccess) local form = getFunction() if clientdata[option] then - form.errtxt = nil - for name,value in pairs(form.value) do - value.errtxt = nil - if value.type == "boolean" then - value.value = (clientdata[name] ~= nil) - elseif value.type == "list" then - value.value = {} - if clientdata[name] and clientdata[name] ~= "" then - for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do - table.insert(value.value, ip) - end - end - else - value.value = clientdata[name] or value.value - end - end + handle_clientdata(form, clientdata) + form = setFunction(form) if not form.errtxt and descr then form.descr = descr |