The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Get variable from JavaScript in PHP
FrostTaco
post May 6 2016, 09:36 PM
Post #1


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



Hi guys, so what i need todo is make a javascript popup, with a textbox where a player can type something. I then need to write what the player typed into a json file(which i know how todo). All i need to know how todo is get the value of prompt("Please enter your trade link", "TradeLink"); in php. smile.gif If this is not possible, then could i prompt the player in php?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 7 2016, 05:11 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



A javascript popup and prompt is not the same thing. If it's a popup containing a real page, then you could let a form in that page submit to the PHP script.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post May 7 2016, 07:22 AM
Post #3


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



Or search for "pass javascript prompt value to php".
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 7 2016, 09:50 AM
Post #4


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(Frederiek @ May 7 2016, 08:22 AM) *

Or search for "pass javascript prompt value to php".

Thanks smile.gif Will tell you if it worked.


QUOTE
A javascript popup and prompt is not the same thing. If it's a popup containing a real page, then you could let a form in that page submit to the PHP script.

Ahh, sorry about that, I meant prompt.


EDIT: I just noticed a problem, the JavaScript runs on page load, and when I click the text(which should make the prompt popup). However, the prompt does not show up on page load, so it causes several problems(The function with the prompt shouldn't even run on page load!). Any idea to fix this?

This post has been edited by FrostTaco: May 7 2016, 10:07 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 7 2016, 10:28 AM
Post #5


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(FrostTaco @ May 7 2016, 04:50 PM) *

the prompt does not show up on page load, so it causes several problems(The function with the prompt shouldn't even run on page load!).

Should it or should it not run on page load? unsure.gif

QUOTE
Any idea to fix this?

Could you post a link or code sample showing the problem?

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 7 2016, 10:55 AM
Post #6


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(Christian J @ May 7 2016, 11:28 AM) *

QUOTE(FrostTaco @ May 7 2016, 04:50 PM) *

the prompt does not show up on page load, so it causes several problems(The function with the prompt shouldn't even run on page load!).

Should it or should it not run on page load? unsure.gif

QUOTE
Any idea to fix this?

Could you post a link or code sample showing the problem?

It should not run on page load.
CODE
document.getElementById('crefer').onclick = function() {
                        var rlink = prompt("Your referal link is http://corndog.corticalcafe.com/?", "ABCYXZ");
                        if(rlink != null){
                            <?php
                                $steam64 = str_replace("http://steamcommunity.com/openid/id", "", $_SESSION['FrostyTaco']);
                                $_SESSION['steam_name'] = $content['response']['players'][0]['personaname'];
                                $name = $_SESSION['steam_name'];
                                $referbuffer = fopen("cache/refer.json", "w+");
                                $rlink = "";
                                $arr = array("$name" => "$rlink");
                                fwrite($referbuffer, json_encode($arr));
                                fclose($referbuffer);
                            ?>
                        }
                    }
The code inside i am working on, but the file is created on page load, and then is edited onclick...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 7 2016, 11:24 AM
Post #7


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



That's the same code snippet as in http://forums.htmlhelp.com/index.php?showtopic=43884, so maybe we should continue the javascript discussion there.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 7 2016, 08:27 PM
Post #8


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(Christian J @ May 7 2016, 12:24 PM) *

That's the same code snippet as in http://forums.htmlhelp.com/index.php?showtopic=43884, so maybe we should continue the javascript discussion there.

ok, totally forgot that post was their xD
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 9 2016, 09:02 PM
Post #9


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(Frederiek @ May 7 2016, 08:22 AM) *

Or search for "pass javascript prompt value to php".

So back to the main question, the easiest way I've found is to redirect the user to www.example.com/?tradelink=blah
Does anyone know of an easier way?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 10 2016, 06:20 AM
Post #10


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



I don't think it gets much easier than that. If you don't want the main page's URL to change, you might load the URL with the querystring in a hidden iframe instead.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 10 2016, 11:01 AM
Post #11


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(Christian J @ May 10 2016, 07:20 AM) *

I don't think it gets much easier than that. If you don't want the main page's URL to change, you might load the URL with the querystring in a hidden iframe instead.

Sorry if this is a dumb question, but i'm not to familiar with iframes. How do I use php to get the querystring in an iframe?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 10 2016, 01:24 PM
Post #12


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



The framed page contains the PHP script. When the parent page requests the framed page from the server, the PHP script in the framed page will run and you can get the framed page's querystring with $_GET as usual.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 10 2016, 01:38 PM
Post #13


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(Christian J @ May 10 2016, 02:24 PM) *

The framed page contains the PHP script. When the parent page requests the framed page from the server, the PHP script in the framed page will run and you can get the framed page's querystring with $_GET as usual.

I think I understand it now, so I have to make a new page, in the frame I open that page(but hidden), the page contains in PHP script, and that page makes the file?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 10 2016, 02:51 PM
Post #14


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(FrostTaco @ May 10 2016, 08:38 PM) *

I think I understand it now, so I have to make a new page, in the frame I open that page(but hidden), the page contains in PHP script, and that page makes the file?

Yes (I assume "the file" is the json file).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 10 2016, 03:11 PM
Post #15


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(Christian J @ May 10 2016, 03:51 PM) *

QUOTE(FrostTaco @ May 10 2016, 08:38 PM) *

I think I understand it now, so I have to make a new page, in the frame I open that page(but hidden), the page contains in PHP script, and that page makes the file?

Yes (I assume "the file" is the json file).

Thanks, it works, just one thing. So when I edit the json file through the website, I also have part of the json file outputted on the site. So I need to refresh the page(not the iframe) after it changed the file, how can I make sure the file is changed before I refresh?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
FrostTaco
post May 10 2016, 05:03 PM
Post #16


Member
***

Group: Members
Posts: 47
Joined: 26-April 16
Member No.: 24,193



QUOTE(FrostTaco @ May 10 2016, 04:11 PM) *

QUOTE(Christian J @ May 10 2016, 03:51 PM) *

QUOTE(FrostTaco @ May 10 2016, 08:38 PM) *

I think I understand it now, so I have to make a new page, in the frame I open that page(but hidden), the page contains in PHP script, and that page makes the file?

Yes (I assume "the file" is the json file).

Thanks, it works, just one thing. So when I edit the json file through the website, I also have part of the json file outputted on the site. So I need to refresh the page(not the iframe) after it changed the file, how can I make sure the file is changed before I refresh?

Nevermind, got it working.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 09:10 AM