![]() |
|
[JavaScript] How to make a Javascript prompt dialog post to PHP? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5) +---- Thread: [JavaScript] How to make a Javascript prompt dialog post to PHP? (/showthread.php?tid=1559605) |
[JavaScript] How to make a Javascript prompt dialog post to PHP? - Dung - Aug 4, 2011 How would I go abouts making a JavaScript show_prompt dialog post to a PHP file on the server? To help better explain, I mean a username and password field much like cPanels login; but I need it to instantly post the data inputed to a server sided php file. Thanks in advance! 🤝 * - bcnboy - Aug 4, 2011 ow It Works Most providers who allow developers to embed JavaScript within their domain force developers to use IFrames to sandbox their code. Facebook has taken a different approach to this problem. JavaScript that you give us gets parsed, and any identifiers (function and variable names) get prepended with your application ID. For example, the following code block: function foo(bar) { var obj = {property: bar}; return obj.property; } becomes: function a12345_foo(a12345_bar) { var a12345_obj = {property: a12345_bar}; return a12345_obj.property; } This creates a virtual scope for every application that runs within Facebook. From there we expose certain functionality through a collection of JavaScript objects that allow you to modify your content on Facebook. Our objects are made to mimic the functionality of JavaScript as closely as possible, but it may take some getting used to for people who are already adept with JavaScript. * - Dung - Aug 4, 2011 That that was completely unrelated to the thread.. thanks for the though O.o * - Dung - Aug 5, 2011 BUMP. Do none of you know programming? -.- * - G-Brain - Aug 5, 2011 What kind of prompt are you talking about? Anyway, as long as you can get user input stored in a variable you can POST it to a PHP file on the same domain using AJAX. You can do AJAX manually but it's easier if you use jQuery or a similar library. Look it up. * - Dung - Aug 5, 2011 '<html> <head> <script type="text/javascript"> function show_prompt() { var name=prompt("Please enter your name","Harry Potter"); if (name!=null && name!="") { document.write("Hello " + name + "! How are you today?"); } } </script> </head> <body> <input type="button" onclick="show_prompt()" value="Show prompt box" /> </body> </html>' Two fields, post to php. No way other than an Ajax? * - G-Brain - Aug 6, 2011 Yes, there's an other way. One the same page you add an HTML form, with method POST and action set to your PHP script. In the form, you add hidden fields. You fill out the form using Javascript and then call its submit() method. Why would you want to do that though? This is a technique used for CSRF, by the way. * - Dung - Aug 6, 2011 (Aug 6, 2011 12:27 AM)G-Brain Wrote: Yes, there's an other way. One the same page you add an HTML form, with method POST and action set to your PHP script. In the form, you add hidden fields. You fill out the form using Javascript and then call its submit() method.Much thanks for pointing me in the right direction. 🤝 Quote:Why would you want to do that though? unique login system Quote:This is a technique used for CSRF, by the way. Hmm.. interesting, perhaps I'll look into it. I've read up a bit on XSS, BeEF etc. Would you be willing to write the script for it? I'll huck you a few LR in a couple days, and can show you a really cool community. :) shoot me a PM * - SB91 - Aug 6, 2011 If it's on the same domain, why wouldn't you use ajax? Here's my jsonp implementation: http://code.google.com/p/jsonp-post/ Basically it simulates cross-domain post requests. |