Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Functionality that allows someone to update a text blurb

    Can somone explain how to implement a web-based script that will allow someone to use a page to enter text that will be displayed (in a designated area) on a home page?

    In other words, I want to be able to update an "Events" section without having to edit the html code.

    Ash

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You need to have a database or a text file that would contain the content. Then using some server side language, you would have to display it on the homepage and write another page that displays the text, and lets someone edit it. Then it saves it back into the database/file.
    OracleGuy

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ugh. Do you know of any tutorials that would explain the procedure?

    ash

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Not off hand, but the code is pretty simple. Which language(s) do you have available to you? ASP, PHP, etc.
    OracleGuy

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP

  • #6
    New Coder
    Join Date
    Oct 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a quick-and-dirty implement. It is very unsecure and isn't as automated as I might like it to be (e.g., create file if non-existent, modify permissions, etc.), but I kept getting errors with those included:

    Take the page you want the information on and put this in it where you want the text to go:

    <?php include('ev_data.txt'); ?>

    Create the file 'ev_data.txt' and put it in the same directory. chmod it to 0666 using an FTP program. Create a new PHP file (preferably with an unguessable filename) and put it in the same directory as the page you just edited. Then just run this file to update the text:

    PHP Code:
    <?php
    $data_file
    ='ev_data.txt';
    $changes='';

    if(isset(
    $contents)) {
          
    $archive=fopen($data_file,'r+');
          
    flock($archive,2);
          
    ftruncate($archive,0);
          
    fputs($archive,$contents);
          
    flock($archive,3);
          
    fclose($archive);
          unset(
    $contents);
         
    $changes='<b>Changes made!</b><br />';
    }

    function 
    getfile($filename) {
       
    $fd fopen($filename"rb");
       
    $content fread($fdfilesize($filename));
      
    fclose($fd);
       return 
    $content;
    }

    $data=getfile($data_file);
    ?>
    <html>
    <head><title>Edit Events:</title></head>
    <body>
    <?php echo $changes?>
    <form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    Edit Events information here:<br />
    <textarea name="contents" rows="20" cols="80" tabindex="2"><?php echo $data;?></textarea><br />
    <input type="submit" name="submitdata" value="Submit changed data" />&nbsp; &nbsp;<input type="reset" name="resetdata" value="Erase data - I'm starting over!" /></form><br />

    Note: data will be unchanged until the "Submit changed data" button is clicked.
    </body></html>

    Anyone else, feel free to post better versions - chmod and fopen kept erroring on me, so creating/chmodding is still a manual job.

    Jeff Walden

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Whoa!

    That works beautifully! Now, to make some minor layout modifications...

    Thanks!

    Ash

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, on second thought, I want to be a nag.

    How would you implement a method to preview the content/text before it's submitted? Maybe a pop-up window that will show how it looks in html?

    Pretty please!

    Ash

  • #9
    New Coder
    Join Date
    Oct 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $data_file
    ='ev_data.txt';
    $changes='';

    if(isset(
    $contents)) {
          
    $archive=fopen($data_file,'r+');
          
    flock($archive,2);
          
    ftruncate($archive,0);
          
    fputs($archive,$contents);
          
    flock($archive,3);
          
    fclose($archive);
          unset(
    $contents);
         
    $changes='<b>Changes made!</b><br />';
    }

    function 
    getfile($filename) {
       
    $fd fopen($filename"rb");
       
    $content fread($fdfilesize($filename));
      
    fclose($fd);
       return 
    $content;
    }

    $data=getfile($data_file);
    ?>
    <html>
    <head>
    <title>Edit Events:</title>
    <script language="Javascript" type="text/javascript"><!--
    function view() {
    q=open("","l","status=0,toolbar=0,width=500,height=500,resizable=1,menubar=1,location=0");
    q.document.open();
    q.document.write(document.forms[0].comments.value);
    q.document.close();
    }

    //--></script>
    </head>
    <body>
    <?php echo $changes?>
    <form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    Edit Events information here:<br />
    <textarea name="contents" rows="20" cols="80" tabindex="2"><?php echo $data;?></textarea><br />
    <input type="button" onclick="view()" />&nbsp; &nbsp;<input type="submit" name="submitdata" value="Submit changed data" />&nbsp; &nbsp;<input type="reset" name="resetdata" value="Erase data - I'm starting over!" /></form><br />

    Note: data will be unchanged until the "Submit changed data" button is clicked.
    </body></html>
    That'll do it. It's not PHP (really Javascript), but you
    use the best tool for the job. By the way, this brings up
    an important point: the code that goes in must be HTML code.
    New paragraphs will show up as spaces only because that's
    how HTML works.

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    Although, I'm getting a js error.

    http://mywebpages.comcast.net/maxpixel/js_error.gif

  • #11
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    I'm going to hazard a guess that "document.forms[0].comments.value is not an object" because there isn't anything on the page called "comments".

    It may be that "document.editform.contents.text" is more successful.

  • #12
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm...I tried document.editform.contents.text and I'm still getting a js error. I've reached an impasse...what else could it be?

    Ash

  • #13
    New Coder
    Join Date
    Oct 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops, copied it from another script and forgot to change the field. The line that looks like this:

    PHP Code:
    q.document.write(document.forms[0].comments.value); 
    should really be this:

    PHP Code:
    q.document.write(document.forms[0].contents.value); 
    That should work a little better ;-).

    Jeff

  • #14
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome! Works beautifully!

    Is there a way to get that pop-up to use the style sheet?

    Reason I ask...the place in which the text is populating has a style/class attached to it:

    <td class="news"><?php include('news/ev_data.txt'); ?></td>

    If this is too much of a pain, I understand. At least I can see if everything is formatted properly. Being able to see the styles would be a bonus!

    Ash

  • #15
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    I'm not sure about this but you might be able to simply change the script slightly.

    Code:
    <script language="Javascript" type="text/javascript"><!--
    function view() {
    q=open("","l"," status=0,toolbar=0,width=500,height=500,resizable=1,menubar=1,location=0");
    q.document.open();
    q.document.write('<link rel=stylesheet href=default.css type=text/css>');
    q.document.write(document.forms[0].comments.value);
    q.document.close();
    }
    
    //--></script>
    OracleGuy


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •