Andreas: leere zeile

Hi

wenn ich meine kleine chatfunktion mal so austeste stell ich fest: das, wenn ich im textfeld alle zeilen vollgeschrieben habe und dann ein leeres eingabefeld absende auch "einmal" eine leere zeile hineingeschrieben wird.
was ich nicht will, also soll bei einer absendung mit leeren eingabefeld keine neue zeile hineingeschrieben
werden.
nun weiss ich nicht genau wie ich dieses bewerkstelligen kann.
propiere auch schon ganz schön lange herum!
kann man da vieleicht irgendwie die formularabsendung sperren?
wenn jemand was weiss dann bitte...

<?php
//File: "mychat.php" - (4.400 Bytes)
//From: "Andreas" - (2004)

$textfile = @fopen("text.txt", "a+");

function input_to_output()
{
    if (!empty($_REQUEST['input']) && !isset($_REQUEST['options'])) {
        $textfile = @fopen("text.txt", "a+");
        fwrite($textfile, $_REQUEST['nick']. ":&nbsp;". $_REQUEST['input']. "\r\n");
        unset($_REQUEST['input']);
    }
    $textfile = file("text.txt");
    foreach ($textfile as $line => $_REQUEST['output']) {
        if ($line < 9) {
            echo $_REQUEST['output'];
            continue;
        }
        else {
            $reset = 0;
            $textfile = file("text.txt");
            unset($textfile[$reset]);
            $set = implode($textfile);
            $textfile = @fopen("text.txt", "w+");
            fwrite($textfile, $set);
            echo $_REQUEST['output'];
            break;
        }
    }
}
?>
<html>
<head>
<title>My Chat</title>
</head>
<body onLoad="document.chat.input.focus()" onContextMenu="return false">
<h1 style="font-family:arial; font-size:18pt;">My Chat</h1>
<form action="mychat.php" method="post" name="chat">
<?php
if (isset($_REQUEST['options'])) {
?>
<hr style="width:45%; text-align:left; border:1px solid #C0C0C0;">
<?php
}
else {
?>
<hr style="width:45%; text-align:left; border:1px solid #000000;">
<?php
}
?>
<table border="0" width="45%" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3">
      <div>&nbsp;</div>
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <div style="font-family:arial; font-size:10pt; font-weight:bold;">Output:</div>
    </td>
    <td>
      <div style="font-family:arial; font-size:10pt; font-weight:bold;">User:</div>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <textarea rows="10" name="output" style="width:82%; font-family:pre; margin-right:2px; overflow-y:hidden;" readonly>
<?php input_to_output(); ?>
      </textarea>
      <textarea rows="10" name="nicks" style="width:17%; font-family:pre; overflow-y:hidden;" readonly>
<?php echo $_REQUEST['nick']. "\n"; ?>
      </textarea>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <div>&nbsp;</div>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <div style="font-family:arial; font-size:10pt; font-weight:bold;">Input:</div>
    </td>
  </tr>
  <tr>
    <td width="45%">
      <input type="text" maxlength="34" name="input" size="34">
    </td>
    <td width="35%" align="left">
      <input type="submit" name="submitter" value="Send"><input type="reset" value="Delete">
    </td>
    <td align="right">
<?php
if (!isset($_REQUEST['options'])) {
?>
      <input type="submit" name="options" value="Options" style="width:65px;">
<?php
}
else {
?>
      <input type="submit" name="ok" value="OK" style="width:65px;">
<?php
}
?>
    </td>
  </tr>
</table>
<br>
<?php
if (isset($_REQUEST['options'])) {
?>
<hr style="width:45%; text-align:left; border:1px solid #000000;">
<div style="font-family:arial; font-size:10pt; font-weight:bold; margin-bottom:2px;">Options:</div>
</table>
<table width="100" cellpadding="0" cellspacing="5" style="border:2px dashed #C0C0C0;">
  <tr>
    <td style="width:50px;">
      <div style="font-family:arial; font-size:8pt; font-weight:bold;">Name:</div>
    </td>
    <td>
      <input type="text" maxlength="8" size="6" name="nick" value="<?php echo $_REQUEST['nick']; ?>" style="font-family:arial; font-size:8pt;">
    </td>
  </tr>
  <tr>
    <td>
      <div style="font-family:arial; font-size:8pt; font-weight:bold;">Chats:</div>
    </td>
    <td>
      <select name="chats" style="font-family:arial; font-size:8pt;">
      <option>Chat-1</option>
      <option>Chat-2</option>
      <option>Chat-3</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>
      <div style="font-family:arial; font-size:8pt; font-weight:bold;">Infos:</div>
    </td>
    <td>
      <input type="checkbox" name="infos" checked>
    </td>
  </tr>
</table>
<br>
<hr style="width:45%; text-align:left; border:1px solid #C0C0C0;">
<?php
}
else {
?>
  <tr>
    <td colspan="3">
      <hr style="width:45%; text-align:left; border:1px solid #C0C0C0;">
    </td>
  </tr>
</table>
<input type="hidden" name="nick" value="<?php echo $_REQUEST['nick']; ?>">
<?php
}
?>
</form>
</body>
</html>

  1. propiere auch schon ganz schön lange herum!

    und nun hab ichs auch hinbekommen:

    function input_to_output()
    {
        if (!empty($_REQUEST['input']) && !isset($_REQUEST['options'])) {
            $textfile = @fopen("text.txt", "a+");
            fwrite($textfile, $_REQUEST['nick']. ":&nbsp;". $_REQUEST['input']. "\r\n");
            unset($_REQUEST['input']);
        }
        else {
            $reset = 10;
            $textfile = file("text.txt");
            unset($textfile[$reset]);
            $set = implode($textfile);
            $textfile = @fopen("text.txt", "w+");
            fwrite($textfile, $set);
            echo $_REQUEST['output'];
        }
        $textfile = file("text.txt");
        foreach ($textfile as $line => $_REQUEST['output']) {
            if ($line < 9) {
                echo $_REQUEST['output'];
                continue;
            }
            else {
                $reset = 0;
                $textfile = file("text.txt");
                unset($textfile[$reset]);
                $set = implode($textfile);
                $textfile = @fopen("text.txt", "w+");
                fwrite($textfile, $set);
                echo $_REQUEST['output'];
                break;
            }
        }
    }