50 users online (1 members and 49 guests)  


  Results 1 to 14 of 14

Related

  1. Comments where and How I want them??? HELP!!!    Forum: Myspace Forum
    Replies: 2
  2. Comments Css Help    Forum: Myspace Forum
    Replies: 1
  3. Replies: 0
  4. Comments on MySpace Page??    Forum: Show it off!
    Replies: 0
  5. submit and thank you page?    Forum: HTML Forum
    Replies: 9
  1. #1
    Glenvern's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2002
    Location
    Norfolk, UK.
    Posts
    112

    Submit comments to the web page

    Can I have my viewers submit a comment onto my website so its visible for all to see and does not disappear until its past it's sell by date.

    Possibly into a scrolling box much the same as I am doing here
    only i do not want a forum or chat room just a box where someone can put a comment..

    The website is an old boys club website with a limited and diminishing number of viewers spread around the world and a box with personal comments would be a nice touch.
    Glenvern

  2. #2
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    If you submit the comments from a simple form into a database, you can have an 'expiry' field, then SELECT all comments where 'expiry' >= today's_date
    The "database" in this instance could be anything from a full-on relational database down to a simple text file!

  3. #3
    Glenvern's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2002
    Location
    Norfolk, UK.
    Posts
    112

    Re: Submit comments to the web page

    The simple data entry form is ok for me to do but not how to enter it into a text file or how to retrieve it then next time the page is opened.

    Is there a ready made that wil do all that or do you know where I can find the coding for this..?

    Thanx for the response DeadMeat
    Glenvern

  4. #4
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    Not sure you can do it from pure HTML. If you want to do it with PHP (obviously you'll need a PHP server!) let me know and I'll bang a demo script together for you to play with
    I'm pretty sure you could use any of the scripting languagues, but PHP's the only one I'm vaguely familiar with ...

  5. #5
    Glenvern's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2002
    Location
    Norfolk, UK.
    Posts
    112

    Re: Submit comments to the web page

    Yes my server does offer Php and MySql if needed - Thanx for the offer to help, much appreciated..
    Glenvern

  6. #6
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    Have a play with this
    form.php - the input page ...
    HTML Code:
    <html>
    <head>
    <meta http-equiv='Content-Language' content='en' />
    <meta name='GENERATOR' content='Zend Studio' />
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
    <title>Comments</title>
    </head>
    <body bgcolor='#FFFFFF' text='#000000' link='#FF9966' vlink='#FF9966' alink='#FFCC99'>
    	<form action='comments.php' method='post'>
    		<label for='comments'>Enter your comments here</label><br />
    		<textarea name='comments' rows='6' cols='64'></textarea><br />
    		<label for='user'>Entered by</label>
    		<input type='text' maxlength='32' size='32' name='user' value='<?php echo "\$username"; ?>'><br />
    		<label for='expiry'>Expiry date</label>
    		<input type='text' maxlength='10' size='10' name='expiry' value='<?php echo date("d/m/Y",strtotime("+28 days")); ?>'><br />
    		<input type='submit' value='Enter Comments' name='done'>
    	</form>
    </body>
    </html>
    comments.php - saves the data (the messy line converts from UK to US dates ... if you're in the US let me know and I'll simplify it!)
    PHP Code:
    <?php
    $fc 
    fopen("comments.txt","a+b");
    fputs($fc,$_POST['comments']."\n");
    fputs($fc,$_POST['user']."\n");
    fputs($fc,strtotime(preg_replace("/^\s*([0-9]{1,2})[\/\. -]+([0-9]{1,2})[\/\. -]+([0-9]{1,4})/""\\2/\\1/\\3"$_POST['expiry']))."\n");
    fclose($fc);
    header("Location: read.php");
    ?>
    read.php - displays the comments if before the expiry.
    PHP Code:
    <?php
    $fc 
    fopen("comments.txt","rb");
    while (!
    feof($fc)) {
        
    $comment fgets($fc);
        
    $user fgets($fc);
        
    $expiry fgets($fc);
        if (
    $expiry time()) {
            echo 
    "Posted by <i>$user</i></br />$comment<hr />";
        }
    }
    fclose($fc);
    ?>
    Notice that if you change the expiry date on the form to today's date, it never shows - I'll leave you to play with that one for now!

  7. #7
    Glenvern's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2002
    Location
    Norfolk, UK.
    Posts
    112

    Re: Submit comments to the web page

    Thank you for that code. I think you may have opened a can of worms for yourself..

    I need to know how to use it now - I can see the HTML bit which is not a problem, but not sure what I should do with the two php codings -

    1. Where/what do I paste them into?
    2. Do I just upload them to my directory? or do I create a php directory for them?.
    3. Where is the comment data stored?
    4. How do I get to it?
    5. Can I remove the data by using the answer to question 4?

    I have removed the username and the expiry date sections, they are not required as they will put there name at the start of the comment..
    So can you remove the relevant php coding for those two bits if it helps in reducing the code..

    I'm in the UK by the way..
    Norfolk born Norfolk bred strong in arm thick in head... as you can see...
    Last edited by Glenvern; 06-20-2006 at 12:44 PM.
    Glenvern

  8. #8
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    Easy bits first:
    Quote Originally Posted by Glenvern
    1. Where/what do I paste them into?
    The three pages will work as posted in files named as in the post.
    Quote Originally Posted by Glenvern
    2. Do I just upload them to my directory? or do I create a php directory for them?
    As written, they will go in any directory - as long as it will serve php files (see the web admin for that ) and they are in the same directory.
    Quote Originally Posted by Glenvern
    3. Where is the comment data stored?
    The coment data is stored in a flat text file - comments.txt - which the comments.php page opens if it exists, or creates if not.
    Quote Originally Posted by Glenvern
    4. How do I get to it?
    Again, as written, the file is stored in the same directory - this can be altered if required
    Quote Originally Posted by Glenvern
    5. Can I remove the data by using the answer to question 4?
    Yes - you can manually edit the comments.txt file, or delete it for a fresh start ...

    I'll look at the rest tomorrow - it's a bit late for me, but it's easy enough to do. I'll try and knock up a line-by-line description so you know what it's doing where, and why ...

  9. #9
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    form.php - the input page ...
    HTML Code:
    <html>
    <head>
    <meta http-equiv='Content-Language' content='en' />
    <meta name='GENERATOR' content='Zend Studio' />
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
    <title>Comments</title>
    </head>
    <body bgcolor='#FFFFFF' text='#000000' link='#FF9966' vlink='#FF9966' alink='#FFCC99'>
    	<form action='comments.php' method='post'>
    		<label for='comments'>Enter your comments here</label><br />
    		<textarea name='comments' rows='6' cols='64'></textarea><br />
    		<input type='submit' value='Enter Comments' name='done'>
    	</form>
    </body>
    </html>
    comments.php - without the option to change the date, this simplifies things ...
    PHP Code:
    <?php
    $fc 
    fopen("comments.txt","a+b"); //opens the file to append new comment - creates it if necessary.
    fputs($fc,$_POST['comments']."\n"); //writes the comments followed by a new line.
    fputs($fc,strtotime("23:59:59 +1 month")."\n"); //sets the expiry date to the end of the day in 1 month's time - this can be altered!
    fclose($fc); //closes the files
    header("Location: read.php"); //redirects to the next page without any visible output.
    ?>
    read.php - displays the comments if before the expiry.
    PHP Code:
    <?php
    $fc 
    fopen("comments.txt","rb"); //opens the comments file for reading
    while (!feof($fc)) { //if the file has not finished
        
    $comment fgets($fc); //put the comment text in a variable.
        
    $expiry fgets($fc); //get the expiry date
        
    if ($expiry time()) { //check the message is not expired
            
    echo "$comment<hr />"//if not expired, display the comment.
        
    }
    //go back and do it all again!
    fclose($fc); //close off the file
    ?>
    Just one thought - I've not checked how well it copes with new lines in the textarea - if you see this before I get time, can you check it for me!

  10. #10
    Glenvern's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2002
    Location
    Norfolk, UK.
    Posts
    112

    Re: Submit comments to the web page

    I have uploaded and given it a test.. couple of snags

    1. It does not retain the box in the page - it opens a new page.
    2. it does not retain the text in the box - when you return to the old page the box is empty.

    Can it be made to look and act like a chat box? and the text remain visible all the time.

    (hope I'm not being too greedy here)..

    If I can PM you the URL you will see what I am hoping to achieve.
    (The website is a personal and private website)
    Glenvern

  11. #11
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    I'm sure it can - and if you PM me the link I'll gladly have a look

  12. #12
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    Just to let you know I've not forgotten you - just been a bit busy.
    Also, if I bump the post someone else might beat me to it!

  13. #13
    Glenvern's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2002
    Location
    Norfolk, UK.
    Posts
    112

    Re: Submit comments to the web page

    Got evrything working ok now except for one small thing -

    When the data appears in the textarea it reads from the top of the file down. I really need it to go to the bottom of the file and then display.. Any idea how do to that.??

    Heres what i got so far--

    <body>
    <?php
    if(array_key_exists('name', $_POST)){
    $fh = fopen('comments.txt', 'a+');
    $fcontent = fread($fh, filesize("comments.txt"));
    $towrite = "\n".$name;
    fwrite($fh, $towrite);
    fclose($fh);
    }
    ?>
    <form method="POST" action"comments.php">
    <label for="comments">Comments</label><br />
    <textarea name="comments" rows="6" cols="64">
    <?php
    echo $fcontent . $towrite
    ?>
    </textarea><br /><br><br>
    <label for="name">Add your 'Name & comment' here then click 'Enter'</label><br />
    <input type="text" size="85" name="name"><br><br>
    <input type="submit" value="Enter" name="submit">
    </form>
    </body>
    Glenvern

  14. #14
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Submit comments to the web page

    If you use r+ instead of a+
    PHP Code:
    $fh fopen('comments.txt''r+'); 
    then the file pointer is placed at the beginning of the file, not the end, so as you read the comments in, the top one will be read first.
    I haven't had time to check this yet, but I assume that with the pointer at the beginning of the file, when you write a new comment it will be inserted.
    This allows you to have a file with the newest comment at the beginning, instead of having to jump to the end then count back.
    Don't forget to reset the pointer to the beginning after writing a new comment (using rewind(), I believe) or it won't appear - as the pointer will be at the end of the newly written comment!
    If that doesn't work as expected, you could read all comments into an array, then reverse the array before outputting it.



Tags for this Thread