Re: ACGI form parsing in OSX?
Re: ACGI form parsing in OSX?
- Subject: Re: ACGI form parsing in OSX?
- From: Gabe Benveniste <email@hidden>
- Date: Thu, 31 Jan 2002 12:38:32 -0800
thanks for the help.
the other problem that i'm having is getting an applescript to continue
running after the return.
here's what i'm trying to do
script processes the forms
returns html to the user, or redirects them
process files on local machine based on form information
On Wednesday, January 30, 2002, at 07:58 PM, James Sentman wrote:
are there any scripting additions like parse CGI that work under OSX?
I've looked at the parsing example on apple.com/applescript and can't
seem to
figure out a simple way to set field values as variables.
any help would be appreciated.
Do you mean how to parse the raw query string and/or post data that
gets sent to you in an acgi script? If so then I might have some
regular applescript code that would help. If I misunderstood the
question, then this wont help;)
property FormKeys : {}
property FormValues : {}
on ParseFormData(RawFormData)
set FormKeys to {}
set FormValues to {}
set TemporaryArray to {}
set SavedDelimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"&"}
set paircount to count of text items in RawFormData
if RawFormData is equal to "" then
return
end if
repeat with i from 1 to paircount
set s to text item i of RawFormData
set TemporaryArray to TemporaryArray & s
end repeat
set AppleScript's text item delimiters to {"="}
set paircount to length of TemporaryArray
repeat with i from 1 to paircount
set thisName to text item 1 of (item i of TemporaryArray)
set thisValue to text item 2 of (item i of TemporaryArray)
set FormKeys to FormKeys & thisName
set FormValues to FormValues & thisValue
end repeat
set AppleScript's text item delimiters to SavedDelimiter
end ParseFormData
on GetFormData(theKey)
set thisCount to length of FormKeys
repeat with i from 1 to thisCount
if item i of FormKeys is equal to theKey then
return item i of FormValues
end if
end repeat
return ""
end GetFormData
Just pass the query string, or the post form data to the ParseFormData
method. that will put the keys and values into 2 arrays. Then use the
GetFormData method to find the key you are looking for and return the
value from the form. Originally I felt that it should be a record
instead of just a pair of arrays, the lookup would be faster, but I ran
into name space problems when names from the forms ran into reserved
words in apple script.
I'm sure it could be done better, but this is very flexible. I'm using
it with the iTunes control script example that I included with the acgi
enabler program for OSX at: http://www.sentman.com/acgi
Sorry if I misunderstood the question.
-James
--
_________________________________________________________________________
James Sentman <email@hidden>
http://www.sentman.com
Enterprise server monitoring with:
http://whistleblower.sentman.com/
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.