Tags:


Advertise here: Contact FM.


forms
June 4, 2006 2:27 PM   RSS feed for this thread Subscribe

Having text from a text area on one page automatically post to a specific area on another.

ok... I'm a bit fuzzy on how to do this and have failed googling it. I am fairly competent at html, and am getting a grasp on CSS, but I think javascript (which I don't know yet) might be what I need to accomplish this task, suggestions on how to do it?

I want to take text entered into text fields on one page of a site and have it show up in a given area of another page automaticly once post is hit. Additionally, any future text entered would automaticly erase what was already posted when it, itself, is posted.
posted by edgeways to computers & internet (17 comments total)
Do you want this to be permanent? If so, you'll need to write the text field info into a database or external file. If it's just temporary, you can easily get the textfield.value and insert it with a id.innerHTML = textfield.value; .
posted by gramcracker at 3:17 PM on June 4, 2006


Are you using frames or are you submitting to a new page?
posted by furtive at 3:17 PM on June 4, 2006


If the text entered needs to visible to other users, you need to store it on the server. Javascript isn't going to help. Use a normal form that submits to a PHP script to store the text and another to read it back whenever a user loads a page.

There are a million ways to do the storage, from storing in a file on disk to using a simple MySQL database. There's nothing terribly hard about this, but it does require learning simple programming and a few other skills.
posted by cillit bang at 3:24 PM on June 4, 2006


I need the next to stay there until something else is entered into the text area, it does not need to be archived or retrievable after it is overwritten..

I was not thinking of using frames, but the text would go into an already existing page, so if frames are needed to accomplish this I can go that route.

The id.innerHTML = textfield.value ... that would be, what, defining a space on a page with a given value that would then receive the value of the textfield? Is there some code example (or tutorial) I can look at that you know of?
posted by edgeways at 3:28 PM on June 4, 2006


I didn't think it would be too hard (or I wouldn't try it), just looking for something that would show me how to do it, or teach me fairly quickly
posted by edgeways at 3:30 PM on June 4, 2006


Do you want to store it for only one visitor? or for anyone who views the page. The former is possible with javascript (with cookies)

the latter, however, would require you to catch the form data on the server, and save it somehow (or archive it, in your terms). Then the HTML which is submitted to each visitor after that must be dynamically altered so as to have that new content.
posted by clord at 3:37 PM on June 4, 2006


ok, thats getting there, good question. It needs to be viewable by everyone who visits, alright. At least I know what's involved now.
posted by edgeways at 3:42 PM on June 4, 2006


One big problem might be the restrictions on cross-site scripting:
One key issue with this is the case where users have more than one browser window open at once. In some instances, a script from one page should be allowed to access data from another page or object, but in others, this should be strictly forbidden, as a malicious website could attempt to steal sensitive information this way. For this reason, the same-origin policy was introduced. Essentially this policy allows any interaction between objects and pages, so long as these objects come from the same domain and over the same protocol. That way, a malicious website wouldn't be able to access sensitive data in another browser window via JavaScript.

posted by smackfu at 3:43 PM on June 4, 2006


there wouldn't be any sensitive information transferred this way.

essentially what I need to do is set up a page where a handful of users log into a given page, type some information into a form (text box) and that info shows up on the front page of their homepage, for everyone to read. The information does not have to have any long term permanency, lasting just until something new is entered.
posted by edgeways at 3:50 PM on June 4, 2006


Running Microsoft IIS is unfashionable these days, so your server probably doesn't support ASP. But if it does, then you can use an application variable to do this -- until the server's restarted, anyway, then you lose it.
posted by kindall at 3:55 PM on June 4, 2006


Here's a simplest case in PHP. It's simplified by combining the two pages, but it shouldn't be hard to separate. It's not fault tolerant or particularly scalable since it uses a flat file. If the users are each changing their own text entry, you'll need to either add another form field for their name/id and create unique files from that (being careful to use basename() or hashes for file security), or, (better idea) work against a database.

<?php
if (isset($_POST['text']))
{
file_put_contents('variable.txt', $_POST['text']);
}
$text = (file_exists('variable.txt'))
? htmlentities(file_get_contents('variable.txt')) # Remove the htmlentities() to allow HTML, else it will change carats to < and >
: ';
?>
<html>
<head><title /></head>
<body>
<div id="prevtext"><?php echo $text; ?></div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="text"></textarea>
<input type="submit" />
</form>
</body>
</html>

posted by moift at 4:07 PM on June 4, 2006


Fudged the formatting again, as I always do. I think the only serious problem though is that the lone quote mark in the second clause of the ternary is supposed to be two, an empty string (which can be any default value).
posted by moift at 4:09 PM on June 4, 2006


thank you
posted by edgeways at 4:13 PM on June 4, 2006


The cross-site scripting thing is completely irrelevant. So are frames, if you want information to get from one user to another.

To do this you need an (extremely simple) server-side scripts, which can be perl or PHP or ASP or any serverside language you want. If you want to store more than one bit of input -- and not have user number 2 just overwrite whatever user number 1 put in, then you'd need to get a bit fancier about how you store and include that input, either with a database or a set of separate textfiles that get read on the server and glued together.

Quick-n-dirty perl example:

To receive the user's input,

#!/usr/bin/perl -w
use CGI;
my $q = new CGI;
my $input = $q->param("theNameOfYourTextarea");
open OUT ">page2.html";
print OUT < eom;br>
(the html for the second page goes here,
blah blah blah, and at some point includes the variable
$input
which will stuff the user's input into page two.)
EOM

print $q->redirect("page2.html");


That's it. Sloppy, probably insecure, and no doubt full of quirks that nitpickers will jump all over me for (including the choice of perl in the first place :) but it'll do what you describe.

Now that I reread, you say you want the text to show up on "their homepage", which implies that there are different homepages for different users(?) If that's the case, this gets a bit more complex, since you have to identify who the user is entering the text to make sure it gets written to the right page, but the general principle is the same.

[on preview, see the PHP version was quicker. Here's perl anyway, just for comparison's sake]
posted by ook at 4:24 PM on June 4, 2006


Formatting screwed up; the print OUT line should be

print OUT <<EOM;
posted by ook at 4:25 PM on June 4, 2006


The fundamental concept that's evading you, edgeways, is client/server.

JavaScript/DHTML/AJAX, whatever, is programming that happens inside a web browser (client). A javascript page you're looking at can make all kinds of cool things happen inside your browser on your computer, but it can't, for very good reasons as mentioned above, make things happen inside my browser on my computer. If it could, you could steal my credit card number.

So what you need, and what you've been given, is server-side code. Code that writes out a text file on your web server which is publicly accessible, so that everyone who comes to your website has access to it.
posted by AmbroseChapel at 4:27 PM on June 4, 2006


Don't know if anyone will read this anymore, but just wanted to say thanks again. The above help pointed me in the direction I needed to look in and I've solved the promblem.. as people have noted it was pretty easy once you knew what you where doing. (as everything is)
posted by edgeways at 8:01 PM on June 8, 2006


« Older What's going on with my Gmail ...   |   I'll be running a skate park l... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Spammers ruin everything: how do I stop them from... June 3, 2008
Making a dumb form smarter March 24, 2008
oh hai, i needs to builds webforms, pls, thx. September 13, 2007
Tricks Involving Concatenation and Pull-Down Menus... July 12, 2007
Software to track project/client information? April 24, 2007