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

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

textEncode and Google Forms

Post by simon.schvartzman » Sun Apr 07, 2019 4:20 pm

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
Simon
________________________________________
To ";" or not to ";" that is the question

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3707
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: textEncode and Google Forms

Post by richmond62 » Sun Apr 07, 2019 6:52 pm

Is your original text htmlText?

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

Re: textEncode and Google Forms

Post by simon.schvartzman » Sun Apr 07, 2019 9:08 pm

@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?
Simon
________________________________________
To ";" or not to ";" that is the question

bogs
Posts: 3912
Joined: Sat Feb 25, 2017 10:45 pm

Re: textEncode and Google Forms

Post by bogs » Sun Apr 07, 2019 10:03 pm

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...
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6226
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: textEncode and Google Forms

Post by dunbarx » Sun Apr 07, 2019 11:33 pm

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

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

Re: textEncode and Google Forms

Post by simon.schvartzman » 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 :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
Simon
________________________________________
To ";" or not to ";" that is the question

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6226
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: textEncode and Google Forms

Post by dunbarx » Mon Apr 08, 2019 2:32 am

Hi.

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

Craig

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

Re: textEncode and Google Forms

Post by jmburnod » Mon Apr 08, 2019 10:36 am

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

bogs
Posts: 3912
Joined: Sat Feb 25, 2017 10:45 pm

Re: textEncode and Google Forms

Post by bogs » Mon Apr 08, 2019 12:08 pm

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.
Image

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

Re: textEncode and Google Forms

Post by jmburnod » Mon Apr 08, 2019 1:38 pm


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

Re: textEncode and Google Forms

Post by simon.schvartzman » Mon Apr 08, 2019 3:40 pm

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
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: textEncode and Google Forms

Post by jacque » Mon Apr 08, 2019 4:48 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: textEncode and Google Forms

Post by simon.schvartzman » Mon Apr 08, 2019 5:02 pm

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
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: textEncode and Google Forms

Post by jacque » Mon Apr 08, 2019 5:35 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: textEncode and Google Forms

Post by simon.schvartzman » Mon Apr 08, 2019 10:15 pm

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...
Simon
________________________________________
To ";" or not to ";" that is the question

Post Reply

Return to “Talking LiveCode”