Jump to content

HTML editting on-site


mortalc

Recommended Posts

Oh dear...um, would I use an XMLHttpRequest object?I would have thought simply adding text to an HTML document would be simple...Oh well. As an alternative, someone mentioned a PHP form earlier. Now, as a first guess, is this the essence of what they meant?

<form method="post"><input type="text" name="reply"></form>//Reply button.<?php//onclickecho $_POST["text"];?>

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Adding text to a HTML page is easy. Adding text dynamically in response to user input is harder. :)You have the framework of a PHP script there (except the index for $_POST is wrong) - now you just need to add the bit where it writes to and reads from a file. Note you'll have to use PHP anyway if you go the AJAX route.And yes, AJAX is just the use of the XMLHttpRequest object.

Link to comment
Share on other sites

O.OI didn't mean dynamically... Although that would be cool...I just meant they type something in a box, click 'reply', and the text is added. Permanently.

Link to comment
Share on other sites

That is dynamic - anything which changes the appearance or content of the site without the underlying HTML being manually modified is considered a "dynamic" action. Only if your site was composed solely of HTML files which never changed until you uploaded newer versions would it be considered "static".

Link to comment
Share on other sites

O.OI didn't mean dynamically... Although that would be cool...I just meant they type something in a box, click 'reply', and the text is added. Permanently.
That is dynamic. Adding something dynamically means you're adding it as you go, after the page is loaded.You will still have to use PHP to save the replies to a file or database, as Synook stated.
Link to comment
Share on other sites

If I'm saving it to a file, how would that work? As in, would a file be openned? Would the user have to write directly into the file? or is it able to write straight to the HTML document?

Adding text to a HTML page is easy. Adding text dynamically in response to user input is harder. :)You have the framework of a PHP script there (except the index for $_POST is wrong) - now you just need to add the bit where it writes to and reads from a file. Note you'll have to use PHP anyway if you go the AJAX route.And yes, AJAX is just the use of the XMLHttpRequest object.
1. What is the correct index? I'm not even sure what that means.2. How would I "add the bit where it writes to and reads from a file"?Sorry, I'm just getting a bit confused on the use of the word 'file'. Is it literally a file? or is it just a way to add to the initial HTML document?
Link to comment
Share on other sites

you should, as everyone has already mentioned you'll need it, start reading up on server-side scripting of some kind. A lot of us here a pretty familiar with PHP. Back to your app, your options are to:1) save the chat as it happens to a file somewhere on the server (easy)2) save the conversation to a database (somewhat harder)Both of which require some sort of server-side scripting interaction. Then you have to either read the database or the file (yes, literally a file, like chat.txt) and show its contents on the page so that the chatters can see the ongoing conversation. Or else it would just be a bunch of text on a server somewhere.In order to have this all happen without the page refreshing, you need to make the part where the file or databases contents are read (in this case the conversation) and displayed on the page happen via AJAX.

Link to comment
Share on other sites

Ok, cool. MySQL is the only one included on the PHP tutorial. Could you give the names and short description (table, text, etc.) of viable ones? or, even better, a link to their tutorial?ED:Hold on - would XML work?ED #2:Yes it would, wouldn't it?I can format text aswell in it, too, can't I?This is brilliant.All I need now is to figure out how to display it as the webpage......but I'm sure that will be in the tutorial.

Link to comment
Share on other sites

Ok, cool. MySQL is the only one included on the PHP tutorial. Could you give the names and short description (table, text, etc.) of viable ones? or, even better, a link to their tutorial?ED:Hold on - would XML work?ED #2:Yes it would, wouldn't it?I can format text aswell in it, too, can't I?This is brilliant.All I need now is to figure out how to display it as the webpage......but I'm sure that will be in the tutorial.
XML will work, but you'll still have to save it to a file in order for this to be permanent. If you aren't worried about losing the conversation when the page is refreshed you don't need to do any of the things listed here except add some text to the innerHTML of a div. But to retain the conversation even after refreshing or closing the browser, you need to store the information in a file or database. The easiest way is to store things in a file. You will need to learn PHP if you want to retain the conversation. There is no other way around it.
Link to comment
Share on other sites

Surely then an XML file would work?Note: when I likened it to Facebook messaging, I didn't mean Facebook Chat. I meant Facebook Messageing. Just to let you know.Also, can there be more than one root element?

Link to comment
Share on other sites

you mean like emailing? Sending messages back and forth like on this forum? That will definitely require a database. (or at least would be the most practical way)

Link to comment
Share on other sites

I've realized a possible problem:I need to be able to have the database viewed within the document.For the File thing - can I upload a text document to the server, and then use PHP to add to it (via reply), and can I have it being viewed above the reply bit, formatted (so with names in Bold)?

Link to comment
Share on other sites

I think you should just start reading the PHP tutorials. All this stuff is in there. TBH, we have no idea the scope of your application, how many users, interface, login systems, etc. If you plan on making this stuff persistent, you will have to store it somehow. If you plan on having people send messages to each other, then it will be easier to do this by creating a table of users, and a table of messages, and then a page for users to see the lists of messages for them. Then you can use CSS to format the PHP code you have written (by outputting HTML).

Link to comment
Share on other sites

incorporating replies is just a matter of linking messages together based on certain criteria.

Link to comment
Share on other sites

Actually, it will just be me and one other. We just need somewhere private to talk. I can go into depth on why if you really want.Here is what I have for the 'reply' code so far:

<?phpfunction Reply(){$file = fopen ("Position.text","a");fwrite ($file, $_POST["reply"]);fclose ($file);}?><form method="post"><input type="text" name="reply" maxlength="50000"></form><button type="button" onclick="<?php Reply() ?>">Reply</button>

Actually, come to think of it, a textarea would be much better. Only, I don't know how to include it in a form - I'm pretty sure that I can't have it as an attribute to an input tag.

Link to comment
Share on other sites

Ok you've got a good start. You don't actually need to put the fopen/fwrite stuff in a function, though. Add an empty action to your form (action='') so it submits to itself. Change your button to a submit button (input type='submit') and remove the onclick event from it. (You can't assign a PHP function to an event handler anyway) It'll have to be moved inside the form too.Then, below your form in the HTML (or above it, whichever you prefer as long as it appears after you've written to the file) create a div which will hold the contents of the file. You'll need to get the contents of the file and loop through them, printing them to the screen.

Link to comment
Share on other sites

Thanks!Is there anyway to use a textarea instead of a text input?Here is what I have so far:

<?phpecho file_get_contents("Position.text");function Reply(){$file = fopen ("Position.text","a");fwrite ($file, "<h3>".<$_POST["name"]."</h3>"."<small>".Date("d.M.Y", "H:i:s")."</small>."<br />".$_POST["reply"]);fclose ($file);}?><form method="post" action="><input type="text" name="reply" maxlength="50000"><button type="submit" ?>">Reply</button></form>

As you can see, I've attempted to format the text and add in the date.

Link to comment
Share on other sites

You only read half of what I wrote. :)

Ok you've got a good start. You don't actually need to put the fopen/fwrite stuff in a function, though. Add an empty action to your form (action='') so it submits to itself. Change your button to a submit button (input type='submit') and remove the onclick event from it. (You can't assign a PHP function to an event handler anyway) It'll have to be moved inside the form too.Then, below your form in the HTML (or above it, whichever you prefer as long as it appears after you've written to the file) create a div which will hold the contents of the file. You'll need to get the contents of the file and loop through them, printing them to the screen.
You can echo the result of file_get_contents but it might not look pretty, and it's going to have the newest messages at the bottom which is going to be a problem because if that information gets really long, every time a user replies, they'll have to scroll to the bottom to see the new message.Oh and action='' is two single quotes. It looks like you just have one double quote. You could use doubles too (action="")
Link to comment
Share on other sites

Oops - I forgot the <input> thing. Perhaps I just confused on how to make the sbutton read "reply".I could have an anchor to send them to the bottom of the page. I think that's possible...How can I have the text both above and after the reply bit?

Link to comment
Share on other sites

Oops - I forgot the <input> thing. Perhaps I just confused on how to make the sbutton read "reply".
The value attribute: <input type='submit' value='Reply' />
I could have an anchor to send them to the bottom of the page. I think that's possible...
Or you could use JavaScript and have a script run in the window.onload event that scrolls the page.
How can I have the text both above and after the reply bit?
?????
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...