Page 1 of 2

textEncode and Google Forms

Posted: Sun Apr 07, 2019 4:20 pm
by simon.schvartzman
Hi, I've using the method described in the post below in order to send data from a mobile LC App to a Google Spreadsheet

https://forums.livecode.com/viewtopic.p ... ms#p171598

So far so good, it works like a charm and gives a relatively easy way to update a Google Spreadsheet which is very useful

Problem I'm facing now is regarding international characters (living in a portuguese speaking country with lots of accents ã, ó, ç)...

This is how my code looks like

Code: Select all

put textEncode(myList,"UTF-8") into tOutput
   post tOutput to URL theURL
in myList I have the information (with accents) and I was hopping textEncode was going to do whatever is necessary to deal with the international formatting but unfortunately is not working. Having or removing the textEncode line of code does not make any difference and the accented character is not shown in the updated Google Sheet.

If I do the update using the Google Form everything works OK so is clear to me that I'm missing something on my LC script.

Any ideas?

Thanks

Re: textEncode and Google Forms

Posted: Sun Apr 07, 2019 6:52 pm
by richmond62
Is your original text htmlText?

Re: textEncode and Google Forms

Posted: Sun Apr 07, 2019 9:08 pm
by simon.schvartzman
@richmond62, many thanks for your answer. I think is leading to fix the problem even though I don't know what to do with it...

My original text (myList) is in a variable (as opposed to be the text of a field) and therefore I don't see how can I define it as being htmlText.

Do I need to have a "fake" field just to deal with the issue?

Re: textEncode and Google Forms

Posted: Sun Apr 07, 2019 10:03 pm
by bogs
simon.schvartzman wrote:
Sun Apr 07, 2019 9:08 pm
My original text (myList) is in a variable (as opposed to be the text of a field) and therefore I don't see how can I define it as being htmlText.
it is pretty easy...
Selection_001.png
htmlText in a variable...

Re: textEncode and Google Forms

Posted: Sun Apr 07, 2019 11:33 pm
by dunbarx
What Bogs said.

What he means is this. In a field, place some text and prettify it. Make the foreGroundColor red and set its style to underline, whatever. In a button somewhere:

Code: Select all

on mouseUp
   get the text of fld 1
    answer it
   
   get the htmlText of fld 1
    answer it
end mouseUp
The data is in a variable. It displays any way you tell it to.

Craig Newman

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 2:26 am
by simon.schvartzman
Thanks @bogs and @craig, reading your answers I guess beside learning LC I have to learn english as well :D.

It seems I am not able to explain myself...but I will try again.

With this code:

Code: Select all

put "simon" into myList
post myList to URL theURL  -- where theURL reproduces a Google Form submission
the Google Sheet behave as expected and shows

simon

but if instead I've this

Code: Select all

put "simão" into myList
post myList to URL theURL  -- where theURL reproduces a Google Form submission
I get

simo

I guess it is safe to came to the conclusion that the missing "ã" has to do with a wrong international character manipulation. How to do it right is what I'm looking for.

Hope is clearer now and any suggestions will be greatly appreciated.

Thanks

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 2:32 am
by dunbarx
Hi.

I never use it, but I bet this is a unicode issue. Others will now chime in.

Craig

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 10:36 am
by jmburnod
Hi All,
As Craig I never used post command but i met issues with accentuated file names.
urlencode/urldecode was the trick for this case
I hope that will be the same for you
Best regards
Jean-Marc

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 12:08 pm
by bogs
simon.schvartzman wrote:
Mon Apr 08, 2019 2:26 am
Thanks @bogs and @craig, reading your answers I guess beside learning LC I have to learn english as well
I'm sorry simon, my post wasn't answering your initial post, it was merely an answer to putting htmlText into a variable, based on Richmond's question.

Richmond does a *lot* involving this type of thing, I thought he might add the further part that solved it once your variable was holding htmlText :oops:

The main part of your question, how to put the accent characters in to the Google Form, was perfectly understandable. Unforutnately, like the others, I don't do much along these lines and have never looked into it personally.

I know I've seen threads talking about accent characters and how to place them though, such as this one, which I'm pretty sure echoes what Jean-Marc said.

Perhaps that may point you in the right direction? Even though they are talking about databases, the encoding itself should be no different no matter where your sending it.

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 1:38 pm
by jmburnod

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 3:40 pm
by simon.schvartzman
Hi all, and many thanks for your inputs. I have followed all the suggestions with no success so far.

In order to make it easier reproduce the issue and play around with all the options I've created a form with just one field. The form can be found here

https://forms.gle/G5kbEpFL3TCQSHrC8


and the associated Google Sheet is here

https://docs.google.com/spreadsheets/d/ ... 1181434727

If the field is filled with international characters they are properly shown in the spreadsheet.

Using the code below a new entry is generated in the spreadsheet but the international characters are dismissed...

Code: Select all

on mouseUp
   -- build form response URL
   put "1XSPVuDOapWz4Iu0cVAWe9YGjWeZ-ia-ZG7yRxzrDses" into myKey
   put  "https://docs.google.com/forms/d/" into theURL
   put myKey & "/formResponse" after theURL
   
   -- build the field 
   put "entry.2124695200=" into tFieldName
   put "xçãáx" into tFieldValue
   put "&" after tFieldValue
   put tFieldName & tFieldValue into theField
   
   put textEncode(theField,"UTF-8") into theField
   answer theField
   
   post theField to URL theURL
end mouseUp
BTW the line of code

put textEncode(theField,"UTF-8") into theField

doesn't make any difference in the end result.

What else can I try?

Is there any way to intercept the browser to see what is being sent by the form submit button?

Many thanks to all of you

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 4:48 pm
by jacque
TextEncode should do it, so that part looks right. The only thing I can think of is that maybe Google is expecting UTF16 or something else. But that seems unusual, most web docs are UTF8. If textDecode with UTF8 works, then that's not the problem.

You might try textEncode on just the field value rather than on the whole POST strimg.

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 5:02 pm
by simon.schvartzman
Thanks Jacque, as a matter of fact I was waiting for your useful answers....

Unfortunately none of the suggestions (UTF-16 nor textEncode just the field) worked

Will keep trying

Regards

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 5:35 pm
by jacque
I'm not familiar with how Google formats its spreadsheets, but maybe there's some flag you need to set to tell it the kind of text you're sending? In other words, maybe it's not the text itself but something in the POST command params.

Re: textEncode and Google Forms

Posted: Mon Apr 08, 2019 10:15 pm
by simon.schvartzman
Found no parameter to be set on the POST command but I made some progress...

The UTF-8 of "Ç" is "%C3%87"

If I use

Code: Select all

put "%C3%87" into tFieldValue
and perform no textEncode the spreadsheets shows the expected result which is of course "Ç"

Question now is why "Ç" is not (correctly) encoded when using

Code: Select all

put textEncode(tFieldValue,"UTF-8") into tOutput
and tOutput remains as "Ç"

Damn Tower of Babel...