textEncode and Google Forms

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5042
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: textEncode and Google Forms

Post by jacque » Tue Apr 09, 2019 2:27 am

Would url Encode be of use here? That's what all the percent signs look like.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2350
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: textEncode and Google Forms

Post by jmburnod » Tue Apr 09, 2019 10:05 am

We noticed url encode make some fantaisies
https://forums.livecode.com/viewtopic.p ... =urlencode

put urlencode("Ç") = %82
put urldecode("%82") = Ç

but if you copy "Ç" from a file name on finder
put urlencode("Ç") = C%3F

Jean-Marc

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 627
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: textEncode and Google Forms

Post by Thierry » Tue Apr 09, 2019 10:34 am

Hi Simon,

Out of curiosity, as I do know nothing about google spreadsheets,
I gave a try and here is working solution with French characters.

Screenshot of your google spreadsheet:

sunnY- 2019-04-09 à 11.20.54.png
and the code:

Code: Select all

on mouseUp
   put "......" into myKey
   put  "https://docs.google.com/forms/d/" into googleSpreadsheetUrl
   put myKey & "/formResponse" after googleSpreadsheetUrl
   
   -- Set http Headers; 1st is mandatory, others I'm not sure
   get "Content-Type: application/x-www-form-urlencoded;charset=utf-8" &CRLF
   get IT &  "Accept-Language: fr-FR" & CRLF
   get IT &  "Content-Language: fr-FR" & CRLF
   set the httpHeaders to IT
   
   put "2 @éè!çàù zzz" into myInput
   
   -- Works fine with datas in LC text field
   -- post libURLFormData("entry.2124695200", textEncode( field "Input", "UTF-8" ) ) to URL googleSpreadsheetUrl
   
   -- Works also fine with datas as a script variable
   post libURLFormData("entry.2124695200", textEncode( myInput, "UTF-8" ) ) to URL googleSpreadsheetUrl
   
   -- check the result
   put IT into url "file:///Users/xx/googleSpreadsheetResult.html"
end mouseUp
Part of the story is to please both LC & Google.

Wish you a nice day,

Thierry
Last edited by Thierry on Wed Apr 10, 2019 8:28 am, edited 1 time in total.
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

simon.schvartzman
Posts: 305
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: textEncode and Google Forms

Post by simon.schvartzman » Tue Apr 09, 2019 11:30 am

Thierry, it works! Well done, I'd have never done it myself.

Thanks god french and portuguese characters are alike...

Many thanks and I'm pretty sure your code will help others in the future.

Abraços!

p.s.: I would like to mention that LC forum members are unbelievable helpful. In my view the forum is probably one of the most valuables attributes of LC. Many thanks to all of you for your contributions.
Simon
________________________________________
To ";" or not to ";" that is the question

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 627
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: textEncode and Google Forms

Post by Thierry » Tue Apr 09, 2019 11:44 am

simon wrote: Thierry, it works! Well done, I'd have never done it myself.

Thanks god french and portuguese characters are alike...
Yes, we are all from the same root :roll:

I believe this will work with any language.... till someone pops up some errors.
Many thanks and I'm pretty sure your code will help others in the future.
I'm glad that it helps you at the first place :wink:

Regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

simon.schvartzman
Posts: 305
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: textEncode and Google Forms

Post by simon.schvartzman » Tue Apr 09, 2019 2:07 pm

Just to expand on the solution and make it more generic (meaning accepting any language) it I found out (https://developer.mozilla.org/en-US/doc ... t-Language) that replacing

Code: Select all

  get IT &  "Accept-Language: fr-FR" & CRLF
   get IT &  "Content-Language: fr-FR" & CRLF
by

Code: Select all

get IT &  "Accept-Language: *" & CRLF
   get IT &  "Content-Language: *" & CRLF
would work with any language.
Simon
________________________________________
To ";" or not to ";" that is the question

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 627
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: textEncode and Google Forms

Post by Thierry » Tue Apr 09, 2019 4:30 pm

Code: Select all

  get IT &  "Accept-Language: fr-FR" & CRLF
   get IT &  "Content-Language: fr-FR" & CRLF
Simon,

I've played a bit with my code and it still works getting rid of these 2 lines of script
but keeping the Content-type settings.

Otherwise, I wouldn't follow you on the generic form.
I believe it's more complicated and depends of use-cases...

May be Sparkout could chime in?

Regards.

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

SparkOut
Posts: 1983
Joined: Sun Sep 23, 2007 4:58 pm

Re: textEncode and Google Forms

Post by SparkOut » Tue Apr 09, 2019 5:08 pm

Did someone call?
I don't know that I am qualified to assume the go-to mantle here, but AFAIK:

It largely depends on use-cases, as Thierry said.

Content-Language is an entity header (server side) and I believe it doesn't have any meaningful purpose in a request header (client side).

Content-Accept is a request header (client side) that provides information to the content provider of the client browser desired or default language setting. If the server has been set up to provide multiple language settings it can provide language-specific content. In theory the server can refuse to serve content where it doesn't have a matching language configuration to the Content-Accept request. I don't imagine there are many servers set up like that. I believe this request header is more usually interpreted as a request to "give me content in this language if you have it, otherwise just provide the content that is nearest the match if you have been set up that way, otherwise just give me content in whatever language you want".

I am more confident of my first answer. I think you should leave out the Content-Language header. But I think either you can leave out the Content-Accept header too, or leave it with your default language choice, and not worry whether the server has that content value, it should return any content rather than refuse just because you said "French please".

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 627
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: textEncode and Google Forms

Post by Thierry » Tue Apr 09, 2019 5:54 pm

SparkOut wrote: Did someone call?
I don't know that I am qualified to assume the go-to mantle here, but AFAIK:
Hi Sparkout,

Everyone is the hero of someone or about something... :D

Thanks for your comment, makes sense.

Interesting, when I started working on Simon's problem, the google answer had wrong characters
for the French part, but afterwards, I got the right wording, like this:

sunnY- 2019-04-09 à 18.52.15.png

Kind regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

Post Reply

Return to “Talking LiveCode”