POST_[] RESULT to TEXT FIELD

Are you using LiveCode to create server scripts or CGIs?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
istech
Posts: 130
Joined: Thu Sep 19, 2013 10:08 am

POST_[] RESULT to TEXT FIELD

Post by istech » Sat Aug 18, 2018 12:56 pm

Hi Livecoders,

Just starting to play with Livecode server and want to POST[] a result to a specific input field on an HTML page.

Very similar to php version <input type="text" name="textname" value="<?php echo $_POST['textnameresult'] ?>" />

If someone could enlighten me that would be great.

Many thanks

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 278
Joined: Tue Apr 10, 2012 9:18 am

Re: POST_[] RESULT to TEXT FIELD

Post by ghettocottage » Sat Aug 18, 2018 4:25 pm

Assuming your variables are "tThis" and "tThat" and "tOther"

Code: Select all

    
    put  "https://yoururl.com"  into gURL
    
    put "this=" & tThis & "&that=" & tThat & "&tid=" & tOther into tStuffToPost   
      
      --post it to the server
      post tStuffToPost to URL gURL
      
      
      --decode the response
      put it into tResults
      
      

istech
Posts: 130
Joined: Thu Sep 19, 2013 10:08 am

Re: POST_[] RESULT to TEXT FIELD

Post by istech » Sat Aug 18, 2018 7:33 pm

ghettocottage wrote:
Sat Aug 18, 2018 4:25 pm
Assuming your variables are "tThis" and "tThat" and "tOther"

Code: Select all

    
    put  "https://yoururl.com"  into gURL
    
    put "this=" & tThis & "&that=" & tThat & "&tid=" & tOther into tStuffToPost   
      
      --post it to the server
      post tStuffToPost to URL gURL
      
      
      --decode the response
      put it into tResults
      
      
Hi there,

Thanks for the response. Just to confirm using my example. If my post looks like:

put "Result" into textnameresult
put "name="testname" & "value=" & textnameresult into tStuffToPost
post tStuffToPost to URL gURL

This should post "Result" to field name testname?

Thanks

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 278
Joined: Tue Apr 10, 2012 9:18 am

Re: POST_[] RESULT to TEXT FIELD

Post by ghettocottage » Sat Aug 18, 2018 8:46 pm

Well, it depends on what your application on the webserver looks like. Is it PHP? Do you have access to the script it is sending to?

istech
Posts: 130
Joined: Thu Sep 19, 2013 10:08 am

Re: POST_[] RESULT to TEXT FIELD

Post by istech » Sun Aug 19, 2018 7:03 am

ghettocottage wrote:
Sat Aug 18, 2018 8:46 pm
Well, it depends on what your application on the webserver looks like. Is it PHP? Do you have access to the script it is sending to?

Hi there,

Yes, it's a simple .lc script I created that I post to and want the result to be displayed in a text box on the same web page. My server has lc server installed so thought there was a straightforward way to do this. Will give this a go. I suppose the php way should also work as I do have php also running but thought there must be a lc way to do the same thing.

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

Re: POST_[] RESULT to TEXT FIELD

Post by SparkOut » Sun Aug 19, 2018 7:57 am

LC server can do this simply.
Php "echo" is equivalent to LC "put".

So you are not trying to fake a user filling in a webform by taking the value in the input box and posting to a url. Instead you are filling the form and posting to the same url and want to redraw the screen with the same form but already filled with the last value submitted?

I'm not sure what you are trying to achieve, but for lc, "put" will be what you need I think.

istech
Posts: 130
Joined: Thu Sep 19, 2013 10:08 am

Re: POST_[] RESULT to TEXT FIELD

Post by istech » Sun Aug 19, 2018 8:28 am

SparkOut wrote:
Sun Aug 19, 2018 7:57 am
LC server can do this simply.
Php "echo" is equivalent to LC "put".

So you are not trying to fake a user filling in a webform by taking the value in the input box and posting to a url. Instead you are filling the form and posting to the same url and want to redraw the screen with the same form but already filled with the last value submitted?

I'm not sure what you are trying to achieve, but for lc, "put" will be what you need I think.
No fake user data being inputted. I have 2 text boxes and a submit button. Users input info into text box 1 and then press submit. Script checks details and replies either ok or error to text box 2. My problem is getting the reply to text box 2.

I just want to put $_POST["result"] into text box 2 on the current webpage.

So under php for my script to work how I want it to I would put the following into text box 2 and it should work "<input type="text" name="textname" value="<?php echo $_POST["result"] ?>" />" what is the lc equivalent?

Very similar to this lesson http://samples.on-rev.com/form.irev but I want the result to go into a text box rather than dynamically displayed.

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 278
Joined: Tue Apr 10, 2012 9:18 am

Re: POST_[] RESULT to TEXT FIELD

Post by ghettocottage » Sun Aug 19, 2018 4:11 pm

Code: Select all

<input type="text" name="textname" value="<?lc put  $_POST["this"] ?>
The "result" I had put in the first code I posted is how to get the response from your remote application. You would not actually use "result" in your web-application and can ignore that bit of code if you do not need it, although it is good for error checking.

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 278
Joined: Tue Apr 10, 2012 9:18 am

Re: POST_[] RESULT to TEXT FIELD

Post by ghettocottage » Sun Aug 19, 2018 4:12 pm

Also, just a thought: you can post directly to your online application and have it process your data and get a response without having to use the html form, unless you just need the person to go to the website for some reason.

Post Reply

Return to “CGIs and the Server”