Highlighted

How do I echo my php to textfield on canvas?

Explorer ,
Mar 26, 2020

Copy link to clipboard

Copied

Hi all, my project is all done, save for this little morsel. Using a small example here. Need to echo the php to a dynamic text box on the canvas.

Here's a php file and its contents:

<?
$ToName = "JohnDoe";
$FromName = "JaneDoe";
echo $ToName;
echo $FromName;
?>

The ajax on the canvas that calls the php file:

	this.frame_0 = function() {
    let params = new URLSearchParams(window.location.search);
    let EcardText = params.get("EcardText");
    return $.ajax({
        url: 'http://www.MYSITE.net/dBText/' + EcardText + '.php',
        type: 'POST',
  	success: function (result) {
 	console.log(result);
  	},
        error: function () {
            console.log('error');
        }
});
//when you call this function
timeline.frame_0()
    .then(res => {
        //do something with the result only here
        console.log(res);
    });
	}

The php file loads and appears in network tab on F12 in the browser. The values John Doe and Jane Doe also appears in the console. After that, all I need to do is execute some lines like this:

this.ToName.text = ToName from my php, should say John Doe

I'm just not sure how to phrase it...

 

Now out of curiosity, I put the following where it says "do something with the result only here" but nothing happens:

this.ToName.text = 'test';

 

Tried it in frame1, it writes test no problem to the textbox. Not sure why it won't execute in the do something with results area, which is where it should be if it's gonna grab the value from the php, right?

 

Thanks all! Stay well.

Views

443

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How do I echo my php to textfield on canvas?

Explorer ,
Mar 26, 2020

Copy link to clipboard

Copied

Hi all, my project is all done, save for this little morsel. Using a small example here. Need to echo the php to a dynamic text box on the canvas.

Here's a php file and its contents:

<?
$ToName = "JohnDoe";
$FromName = "JaneDoe";
echo $ToName;
echo $FromName;
?>

The ajax on the canvas that calls the php file:

	this.frame_0 = function() {
    let params = new URLSearchParams(window.location.search);
    let EcardText = params.get("EcardText");
    return $.ajax({
        url: 'http://www.MYSITE.net/dBText/' + EcardText + '.php',
        type: 'POST',
  	success: function (result) {
 	console.log(result);
  	},
        error: function () {
            console.log('error');
        }
});
//when you call this function
timeline.frame_0()
    .then(res => {
        //do something with the result only here
        console.log(res);
    });
	}

The php file loads and appears in network tab on F12 in the browser. The values John Doe and Jane Doe also appears in the console. After that, all I need to do is execute some lines like this:

this.ToName.text = ToName from my php, should say John Doe

I'm just not sure how to phrase it...

 

Now out of curiosity, I put the following where it says "do something with the result only here" but nothing happens:

this.ToName.text = 'test';

 

Tried it in frame1, it writes test no problem to the textbox. Not sure why it won't execute in the do something with results area, which is where it should be if it's gonna grab the value from the php, right?

 

Thanks all! Stay well.

Views

444

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 26, 2020 0
Adobe Community Professional ,
Mar 27, 2020

Copy link to clipboard

Copied

First, your code will fail on Internet Explorer because you're using ES6 functionality that it doesn't support.

 

Second, using PHP code just to pass data is a strange choice. This is literally what JSON is for.

 

Third, "this" inside event handlers always points to the global window object. You must either use .bind() on the event handler function to force it execute in the desired context, or have your function use the global variable exportRoot which points to the root timeline, or declare a local alias to "this" in the event handler's scope. There are numerous threads on these forums discussing this issue.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 27, 2020 0
Explorer ,
Mar 27, 2020

Copy link to clipboard

Copied

exportRoot made it start writing to text. not sure about the ES6 stuff, someone from reddit suggested it. the site was originally from flashkit, it was a php flash thing. I used it for a while, but then HTML5 happened. others were wondering if it could all be converted for canvas, so I went about doing so, preferably keeping it as close to the original as possible.

 

all that's left now is to echo to the textbox. might you know? thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 27, 2020 0
ClayUUID LATEST
Adobe Community Professional ,
Mar 27, 2020

Copy link to clipboard

Copied

I wouldn't use PHP at all for just passing variable values. That's bonkers. Use JSON.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 27, 2020 0