Jump to content


Photo

Php Form to File


  • Please log in to reply
12 replies to this topic

#1 skroks609

skroks609
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 06 August 2006 - 08:15 PM

Ok, i posted this earlier but i want to try again because none of the stuff i was told to do were working for me :(
i need to write a form that sends a nickname and a message to a file called messageview.html . any ideas?
All windows computers will crash in 2057
Or will they??...

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 06 August 2006 - 08:21 PM

What do you mean exactly? You want it to modify a html file?

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 skroks609

skroks609
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 06 August 2006 - 08:26 PM

I would like it so a form adds a line of text to the messageview.html file but i dont understand how to do it proberly as all i'm getting is errors :(
All windows computers will crash in 2057
Or will they??...

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 06 August 2006 - 08:33 PM

You mean let's say messageview.html looks like this:
<html>
<head>
<title>Something</title>
</head>
<body>

And you want to have a form so when you enter: "1,2,3", messageview.html will become:
<html>
<head>
<title>Something</title>
</head>
<body>
1,2,3


??

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 skroks609

skroks609
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 06 August 2006 - 08:39 PM

yes thats what i mean....

also i am stuck on level 4 of your riddle lol
All windows computers will crash in 2057
Or will they??...

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 06 August 2006 - 08:48 PM

In that case, I recomend you to do something like this:
make messageview.html a php file (for example messageview.php?), and make it look like this:
<html>
<head>
<title>Title</title>
</head>
<body>
<?php include("messages.txt"); ?>
</body>
</html>

Now, Google for a tutorial about php and files, and how to write to files. Use that tutorial to make your script, that will write what ever you want to add into messages.txt. Every time someone opens messageview.php, he will see everything that was added with the form.
I am not going to make the script for you, find one on google.

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 06 August 2006 - 08:48 PM

they probably are going to merge this... however i'm only here to help you (again) ;D

<?php
$PreCheckComplete=0;
if ($_POST['submit']) {
   $Error='';

   $Name = $_POST['name'];
   if (!$Name) $Error .= "&bull; Name is a required field.<br>";
   if (strip_tags($Name) != $Name) $Error .= "&bull; You are not allowed to use html in your name.<br>";
   if (strlen($Name) < 3) $Error .= "&bull; Your name must atleast contain 3 characters.<br>";

   $Email = $_POST['email'];
   // TODO: perform an regex on email when provided.
   if ($Email) {
      if (strip_tags($Email) != $Email) $Error .= "&bull; You are not allowed to use html in your e-mail.<br>";
   }
   
   $Website = $_POST['website'];
   // TODO: perform an regex on website when provided.
   if ($Website) {
      if (strip_tags($Website) != $Website) $Error .= "&bull; You are not allowed to use html in your website address.<br>";
   }

   $Comment = $_POST['comment'];
   if (!$Comment) $Error .= "&bull; Comment is a required field.<br>";
   if (strip_tags($Comment) != $Comment) $Error .= "&bull; You are not allowed to use html in your comment.<br>";
   if (strlen($Comment) < 10) $Error .= "&bull; Please make sure your comment atleast contain 10 characters.<br>";

   if ($Error) {
      echo "<div class='Error'>$Error</div>";
   } else {
      $PreCheckComplete=1;
      $Error = '';
      $Entry = "<div class='userdetails'>Name: " . $Name;
      if ($Email) $Entry .= "<br>e-Mail: <a href='mailto:" . $Email . "'>".$Email."</a>";
      $Entry .= "</div>";
      if ($Website) $Entry .= "<a href='http://".str_replace('http://', '', $Website)."'>$Website</a>";
      $Entry .= "<div class='comment'>$Comment</div>";
      $Source = "messageview.html";
      if (!($Resource = fopen($Source, "a"))) {// a because we always want to add data on the last line..
         $Error .= "WARNING: Could not open file.<br>";
      }
      if (!flock($Resource, LOCK_EX)) {
         $Error .= "WARNING: Could not lock file.<br>";
      }
      if (!fwrite($Resource, $Entry)) {
         $Error .= "WARNING: Could not write to file.<br>";
      }
      if (!flock($Resource, LOCK_UN)) {
         $Error .= "WARNING: Could not unlock the file.<br>";
      }
      if (!fclose($Resource)) {
         $Error .= "WARNING: Could not close file.<br>";
      }
      if ($Error) {
         echo "<div class='Error'>$Error</div>";
      }
   }
}
if ($PreCheckComplete==0) {//Display the form.
?>
<form action="" method="post">
<h3>All fields marked with * are mandatory.</h3>
<table width="100%" cellpadding="0" cellspacing="0">
<tr><td>* Name:</td><td><input type="text" name="username" value="<?php echo @$_POST['username'] ? $_POST['username'] : '';?>"></td></tr>
<tr><td>E-mail:</td><td><input type="text" name="email" value="<?php echo @$_POST['email'] ? $_POST['email'] : '';?>"></td></tr>
<tr><td>website:</td><td><input type="text" name="website" value="<?php echo @$_POST['website'] ? $_POST['website'] : '';?>"></td></tr>
<tr><td>*comment:</td><td><textarea style="width:100%" rows="15" name="comment"><?php echo @$_POST['comment'] ? $_POST['comment'] : '';?></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="add to guestbook"></td></tr>
</table>
</form>
<?php } ?>


#8 skroks609

skroks609
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 07 August 2006 - 08:36 AM

thanx guys!!  ;D But is there any way to turn all the txt stuff into a different font? or colours?
All windows computers will crash in 2057
Or will they??...

#9 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 07 August 2006 - 08:50 AM

You should look into BBcode.

Orio.
Think you're smarty?

(Gone until 20 to November)

#10 skroks609

skroks609
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 07 August 2006 - 08:57 AM

hmmm...
is there any way to modify
<?php include("messages.txt"); ?>
to make it have different fonts or colours?
All windows computers will crash in 2057
Or will they??...

#11 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 07 August 2006 - 08:59 AM

You should look into BBcode.

Orio.


Think you're smarty?

(Gone until 20 to November)

#12 skroks609

skroks609
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 07 August 2006 - 09:00 AM

ok lol
All windows computers will crash in 2057
Or will they??...

#13 skroks609

skroks609
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 07 August 2006 - 09:02 AM

anyway... logging off now see ya and thanx for all the help!  :D
All windows computers will crash in 2057
Or will they??...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users