Staredit Network

Staredit Network -> Computers and Technical -> Entry form
Report, edit, etc...Posted by Wilhelm on 2006-04-10 at 22:43:38
I'm getting annoyed at having to format text whenever I make an update on my site's main page. What I want is a simple form that will let someone (me) enter in a post and who it is posting it, then append the time at the end in a smaller font. It should look something like this:

Site is updated now. Woot.

Wilhelm - 10:42 AM 4/10/06

I understand HTML. I get forms. Anything beyond that... no.
Report, edit, etc...Posted by Centreri on 2006-04-11 at 16:36:06
There was a simple way to do it using forums and accessing the data.
If you have a forum, simply post the text there, then make it so that the page accesses it through the MySQL database. The tough part is making the text formatting apply correctly and all that (never finished this). Just edit it somehow to also show the date and the person (that part is easy - it's also saved in the database so you just have to access specific parts of the database).

I don't have the code from the top of my head because it was lost (somehow) and I haven't PHP'ed in a while. If you have no PHP/MySQL Forums, skip this post (should have said that first, shouldn't I tongue.gif).

Search the internet for something like that. Oh, and your server has to support PHP and you have to have a MySQL database thingie for that to work tongue.gif.

Remember to put the data in a hidden forum. You don't want ppl running across your magical box of site control pinch.gif.
Report, edit, etc...Posted by Shmeeps on 2006-04-11 at 20:35:29
You can do it without MySQL too. ALl you do is have the form input, then on the next page, use str_replace to change all the enters into <br />s, then do like

CODE

$user = $_POST['user'];
$news = $_POST['news'];
$time = date("DATE CODE");
$news .= "<br /><hr /><br />{$user} - {$time}";


Where date code is the letters representing how you want your date displayed.

Then use fopen and fwrite to write it to a file. You can do it with a MySql Database too, your choice.

This of course, is the simplest way. If you want like, customizable time, add another column for time and put it in there, then parse it and display it as the people want. Still, this will work for the basic of things.
Report, edit, etc...Posted by Wilhelm on 2006-04-11 at 20:51:10
fopen? fwrite? I sorta understand the code, but I'm otherwise lost. The tutorial I looked at said I had to make a PHP page to send the data to, but then it descended into coding gibberish and I got totally lost. Is this "next page" business the PHP file that I'm sending the data to and the code you posted how it will handle the data?
Report, edit, etc...Posted by Doodle77(MM) on 2006-04-11 at 21:48:23
Serialization of arrays is what I have found to be the easiest way to store indexed data (such as newsposts)

ADDITION:
You can use my newsposting system if you want to, It pretty much has the framework down, just no comments.
Report, edit, etc...Posted by Shmeeps on 2006-04-11 at 22:38:33
It'd be something like this, assuming you are using a MySql Database. If Not I can write out the file writing code too.

Page1:
CODE

HTML, Forms, Ect, send to Page 2, something like

<form action="page2.php" method="post">
<input type="text" name="user" />
<textarea cols="80" rows="20" name="text"></textarea>
<input type="submit" name='Submit" value="Submit" />
</form>


Page2:
CODE

<?
$text = $_POST['text'];
$user = $_POST['user'];
$time = date("g:j A d/m/y");

$text = str_replace("
", "<br />", $text);

$text .= "<br /><br /><hr /><br />{$user} - {$time}";

mysql_connect(CONNECTION DETAILS);
mysql_select_db();

mysql_query("INSERT INTO `News` (`News`) VALUES ('$text');
?>


This will chagen all your returns into a <br /> so it displays and stores correctly, then add the date/user stamp, then put it into your database. Of course, you'll have to change the queries to you own needs, but, it should be a start.
Report, edit, etc...Posted by Wilhelm on 2006-04-11 at 22:54:56
My current host does not allow server side scripting unless I apply for it (and my site isn't that impressive, really). As for the query bit, I would replacing "news" with the page that I'm putting it to, right?
Report, edit, etc...Posted by Shmeeps on 2006-04-11 at 23:09:26
No, it depends on your table names.

I'd assumed that something like Javascript maybe could do this, but I don't use it so I'm not sure. Really, and language that can write somewhere (File Database, ect) where it wont get deleted could do it.
Report, edit, etc...Posted by Wilhelm on 2006-04-12 at 00:40:12
Well... what languages... can do that... ermm.gif
Report, edit, etc...Posted by Centreri on 2006-04-12 at 15:06:00
I really doubt you can do it without server-side scripting because if it's browser side, like javascript, you're trying to get the browser to create a file or store something.. won't work.
Report, edit, etc...Posted by Shmeeps on 2006-04-12 at 20:12:30
Flash might work, dunno though.

I don't know of all the langauges that can do it, I know PHP, ASP, and CGI could do it, but those are all server side. A quick google search might be appropriate here.
Report, edit, etc...Posted by Doodle77(MM) on 2006-04-12 at 20:26:33
if you have no server-side scripting you will need to update your site by editing the HTML. Sorry. I guess you can run your site on your own computer like I do.
Report, edit, etc...Posted by Wilhelm on 2006-04-12 at 21:27:12
Does the free DNS thing allow server side languages/etc? I've looked at the site and I'm pretty damn confused.
Report, edit, etc...Posted by RexyRex on 2006-04-13 at 02:00:18
If you don't mind registering, here's a fully working script I made a long time ago. smile.gif
http://www.codedfx.com/forums/index.php?showtopic=6779

P.S. You don't have to post, just need an account to see the thead. mellow.gif
Report, edit, etc...Posted by Wilhelm on 2006-04-15 at 19:59:10
Can anyone correct the code modifications I made to Rexy's script? It wont' output a proper HTML page, and I don't really know why.
form_handler.php
CODE
<?php
//Check for input in all areas and if there isn't any, redirect.
if( (empty($_POST['name']) || empty($_POST['content'])) && isset($_SERVER['HTTP_REFERER']) ) {
header("Location: ".$_SERVER['HTTP_REFERER']);
exit();
} else if( (empty($_POST['name']) || empty($_POST['content'])) && !isset($_SERVER['HTTP_REFERER']) ) {
header("Location: ".dirname($_SERVER['PHP_SELF']));
exit();
} else if( !empty($_POST['name']) && !empty($_POST['content']) ) {

// See data_display.php for information on this bit of code.
$filesize = filesize("data.html");

//Clean up inputs
$_POST['name'] = trim($_POST['name']);
$_POST['content'] = trim($_POST['content']);

//HTML is allowed, so check for magic quotes and remove them if they're there.
if( !ini_get("magic_quotes_runtime") )
{
 $_POST['name'] = stripslashes($_POST['name']);
 $_POST['content'] = stripslashes($_POST['content']);
}

// Replace content not supported by the parser with HTML.
$_POST['content'] = str_replace("\n","<br />",$_POST['content']);
$_POST['content'] = str_replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;",$_POST['content']);
$_POST['name']    = str_replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;",$_POST['name']);
$_POST['content'] = str_replace("&","&amp;",$_POST['content']);
$_POST['name']    = str_replace("&","&amp;",$_POST['name']);


// Just grabbing the file contents...
$handle = fopen("data.html","r");
$readData = @fread($handle,$filesize);
fclose($handle);

// Opens the file containing the posted information as writeable, script halts on error.
$handle = fopen("data.html","w+") or die("Could not open the target file for writing or the file did not exist.");

if( $filesize > 1 ) {
 $data = $_POST['name']."\t".time()."\t".$_POST['content']."&&".$readData;
}

if( $filesize < 1 ) {
 $data = $_POST['name']."\t".time()."\t".$_POST['content'];
}

// Write the data and close the handle.
fwrite($handle,$data);
fclose($handle);
unset($handle);

header("Location: ".$_SERVER['HTTP_REFERER']);
}

data_handler.php
CODE
<?php
$output = null;

// Opens the file containing the posted information as readonly, script halts on error.
$handle = fopen("data.html","r") or die("Could not open the source file for reading.");


// Assigns all of the data to a variable, posts are separated by two '&' characters in the file.
// Additonally, if the filesize is blank than it will not be read and a message will be outputted instead.
$filesize = filesize("data.html");

if($filesize < 1) {
die("The source file has no content.");
}

// Read the data from the file and put it into a variable.
$data = fread($handle,$filesize);

// Split up the posts.
$posts = explode("&&",$data);

// For each post, do the following HTML and add the data from the posts to the output variable.
foreach($posts as $tempValue) {
$postData = explode("\t",$tempValue);

//HTML
$output .= <<<OUTPUT
<table border="1">
<tr>
 <td>
OUTPUT;
//End HTML

$output .= $postData[0];

//HTML
$output .= <<<OUTPUT
 </td>
 <td>
OUTPUT;
//End HTML

$output .= date("F nS l g:m a",$postData[1]); //Look at the PHP date function for more info on displaying this

//HTML
$output .= <<<OUTPUT
 </td>
</tr>
<tr>
 <td colspan="2">
OUTPUT;
//End HTML

$output .= $postData[2];

//HTML
$output .= <<<OUTPUT
 </td>
</tr>
</table>
<br />

OUTPUT;
//End HTML
}

// Starts output buffering and compresses the output if the server allows (to save bandwidth).
ob_start("ob_gzhandler");
echo $output;
ob_end_flush();
?>
Report, edit, etc...Posted by Centreri on 2006-04-16 at 15:05:30
I'll try making an easier to use script for it. In the meantime, PHP files won't work with a host that doesn't support PHP. IE can still display the pages, but it'll display the PHP parts as plain text while converting the HTML tags correctly. FF will simply show just the source code.
Report, edit, etc...Posted by Wilhelm on 2006-04-16 at 20:22:43
Kay, I intend to use the resulting HTML page anyways.
Report, edit, etc...Posted by BeeR_KeG on 2006-04-16 at 21:18:37
I'd rather not use PHP code unless I know hot to work most of it. I'd really have to get an error and not know what to do, but that's just me.

Anyways, those 2 pages of PHP scoding that you've posted seems very long for what you want it do do. I'd just create an HTML form and have that be queried to the PHP display page which contains all the HTML. Just automatically echo all the HTML tables and put the text inside it.
I might make it much shorter, the only thing is that I don't know how to store the same variable's different values when making different News Post.
Report, edit, etc...Posted by Wilhelm on 2006-04-16 at 21:26:04
Unfortunately, I don't know PHP one lick. I figure it's probably not worth learning it if I'm just gonna have one page using it. At this rate, looks like I might have to... =/
Next Page (1)