Page 2 of 2

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 2:27 am
by jacque
Would url Encode be of use here? That's what all the percent signs look like.

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 10:05 am
by jmburnod
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

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 10:34 am
by Thierry
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

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 11:30 am
by simon.schvartzman
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.

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 11:44 am
by Thierry
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

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 2:07 pm
by simon.schvartzman
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.

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 4:30 pm
by Thierry

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

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 5:08 pm
by SparkOut
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".

Re: textEncode and Google Forms

Posted: Tue Apr 09, 2019 5:54 pm
by Thierry
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