What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » javascript POST?

Pages: (2): « First [ 1 ] 2 » Last »
javascript POST?
Author: Message:
bach_m
Veteran Member
*****

Avatar
4837 :P

Posts: 2863
Reputation: 7
37 / Male / –
Joined: Feb 2003
O.P. javascript POST?
i'm looking for a javascript box to popup and ask for a name, and then pass that to my website as POST data, for use in a PHP script. can it be done??? i dont know the first thing about PHP...
02-20-2004 03:02 AM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: javascript POST?
Why can't you use GET? I think that would be easier... :-/

I'm not great at JavaScript, but I think the only way to pass a value via POST is to make a form in your page with a hidden field. You can then set the field to the value returned by the JS prompt function, and submit the form using JavaScript.

(I'm not going to post example code... not enough time :p)

This post was edited on 02-20-2004 at 04:34 AM by WDZ.
02-20-2004 04:32 AM
Profile PM Web Find Quote Report
fluffy_lobster
Veteran Member
*****

Avatar
Posts: -2

Posts: 1391
Reputation: 23
36 / Male / Flag
Joined: Nov 2002
RE: javascript POST?
You can also do it without changing the main page's navigation by using an iframe.  I'll do a quick dummy example:

First you make a page with your form on it, say it was called hiddenform.htm:
code:
<form name="hiddenForm" method="POST" target="myurlwhichtakespostdata.php"><input type="hidden" id="variableToSend" value=""></form>
Once you've done that, you can stick it on the following page with all the relevant javascript:
code:
<script language="Javascript"><!-- function sendData(theData){
document.all.myiFrame.getElementById('variableToSend').value = theData ;
document.all.myiFrame.forms['hiddenForm'].submit() ;
}
-->
</script>


<!-- All your page scripting here, run the javascript function sendData('whatever') when you wanna send the data -->

<iframe src="hiddenform.htm" frameborder="0" scrolling="NO" width="1" height="1"></iframe>
And you're done :P (Y)
02-20-2004 09:31 AM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: javascript POST?
There is no need for an iframe at all if you just want to popup a inputbox and then redirect the current page to your website... If you do want that the main page (where the popup is launched) to stay, then you can use Lobster's method...

So, it depends what you want.
Do you want that popup at you website which also takes the data (name)?
Do you want to be redirected to your website after the name is filled out?
Is it nessecary to use the POST method? Can't you use the GET method?
Can you be more clear about what you exactly to happen and where it should happen (in clear steps)?

for example:
(the user will not know what happens with his name after he filled it in.)
1) User opens page A
2) a popup is shown asking for his name and the data is send to page B (your website)
3) the user stays on page A

or for example:
(the user is redirected to the page which processes the name.)
1) User opens page A (your website)
2) a popup is shown asking for his name and the data is send to page B
3) that page B processes the name and outputs some data accordingly. For example: "Hi, <name>. Welcome at my website"

This post was edited on 02-20-2004 at 11:00 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
02-20-2004 10:55 AM
Profile PM Find Quote Report
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
RE: javascript POST?
If you know sessions you can use them, they're very confortable. Although I don't really know how to manage them :grin:

Really interesting for what you want to do. :)
02-20-2004 11:57 AM
Profile E-Mail PM Web Find Quote Report
bach_m
Veteran Member
*****

Avatar
4837 :P

Posts: 2863
Reputation: 7
37 / Male / –
Joined: Feb 2003
O.P. RE: javascript POST?
quote:
Originally posted by CookieRevised

(the user is redirected to the page which processes the name.)
1) User opens page A (your website)
2) a popup is shown asking for his name and the data is send to page B
3) that page B processes the name and outputs some data accordingly. For example: "Hi, <name>. Welcome at my website"

this one..

i'd prefer to not divulge WHY i need it. but i need it to be processed by a PHP script. for instance. they open a page. checks whether thay have a cookie saying that they have given their name (and what ;)), and if not, then it pops up a box saying"whats ur name?", and then submits that to my main page, which proceces that.

i'd prefer not to use get, but if absolutely necesary, i guess i can
02-20-2004 12:04 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: javascript POST?
It still isn't exactly clear what you want to do. Explain in clear steps and give each page/link a name ;)

But IF I read you correctly then with GET-method this is very easy todo...

in the page A you have to make a script which:
1) Check for cookie
2) if exist then reload page with page C
3) if it doesn't exist, ask for name and reload with page B

C and B can be the same page actually if you check in that page if something is added to the URL.

Even more: A, B and C can be the same page if you use this structure:
1) load the page
2) check if a cookie exist
4) if it exist, read it/process it load the page further...
3) if not then ask for a name, create the cookie, and load the page further...

There is no need for a form if you do that. All this can be done in plain javascript (or convert everything to php if you like). In Javascript it would be something like this:
code:
<html>
  <head>
    <title>Main Page</title>
    <script language="JavaScript">
      // Get the users name from a cookie,
      // if it doesn't exist then ask for it and create the cookie.
      var username = unescape(document.cookie)
      username = username.split("=")
      if (username == "") {
        username = prompt("What is your name?","")
        var expiredate = new Date()
        expiredate.setMonth(expiredate.getMonth() + 1)
        document.cookie = "Name=" + username + ";expires=" + expiredate.toGMTString() + ";path=/"
      }
      //
      // put your processes here, the variable username will hold the value of the name.
      //
    </script>
  </head>

  <body>
    normal page
  </body>
</html>

not tested

This post was edited on 02-20-2004 at 02:22 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
02-20-2004 01:41 PM
Profile PM Find Quote Report
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
RE: javascript POST?
quote:
Originally posted by bach_m
then it pops up a box saying"whats ur name?", and then submits that to my main page, which proceces that.
Sessions are perfect for this kind of thing:
That's variabales that are stores in the server and are kept alive while the session is alive (like in these forums) and they can be accessed from any php in the server.
So you can store the data from your pop-up to the session-vars and retrieve it from the main-page. All this occurs in the darkness so nobody has control over it (php-sessions is the most secure way to send and recieve data).
02-20-2004 02:45 PM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: javascript POST?
quote:
Originally posted by KeyStorm
Sessions are perfect for this kind of thing:
I dunno about that... seems kinda overkill... :p

If you're just passing one variable to one other page, you should just use the JavaScript POST thing as shown above. Even if you used sessions, you'd still have to do the same thing to get the value from JavaScript to PHP.

Also, sessions expire (default time is like half an hour), and are designed to exist only during one visit to the site. If you want your users' data to still be available when they return tomorrow, you should use cookies. If for some reason you don't want the data stored in cookies, store it in a database with some kind of ID associated with it, then put the ID in a cookie.
02-20-2004 03:39 PM
Profile PM Web Find Quote Report
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
RE: javascript POST?
Remember you can read and set cookies in PHP ;)
02-20-2004 04:19 PM
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On