• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PHP] Help with Form
#1
Hello,
So I made this form that edits a .txt when you enter the the text then sumbit it. What i need help with is how would I get it to enter an extra comma at the beginning without entering it into the textbox?

I already tried
PHP Code:
$add $_POST['addition'] + ", "

But no luck. Any way I can do this?

Heres the code:
PHP Code:
<?php
$fn 
"test.txt"
$file fopen($fn"a+"); 
$size filesize($fn);
if(
$_POST['addition']) fwrite($file,$_POST['addition']); 

$text fread($file$size); 
fclose($file); 
?> 
<form action="<?=$PHP_SELF?>" method="post"> 
<textarea><?=$text?></textarea><br/> 
<input type="text" name="addition"/> 
<input type="submit"/> 
</form> 

Any help is appreciated Angel
Thanks,
ScHmIdTy
[Image: ScHmIdTy56789.png]
  Reply
#2
Nevermind, I got it.
[Image: ScHmIdTy56789.png]
  Reply
#3
If I understand what it is you are looking for...

change:
PHP Code:
fwrite($file,$_POST['addition']) 

to:
PHP Code:
fwrite($file,$_POST['addition'] . ","
  Reply
#4
also
PHP Code
  1. $add = $_POST['addition'] + ", ";
  2. echo $add; //output: 0; independently of the input.


Also I would scan for commas in the input to prevent your file getting fucked up.
  Reply
#5
(03-26-2012, 01:09)sac0o01 Wrote: If I understand what it is you are looking for...

change:
PHP Code:
fwrite($file,$_POST['addition']) 

to:
PHP Code:
fwrite($file,$_POST['addition'] . ","

Well that works too Big Grin


I put:
PHP Code:
$together ", " htmlspecialchars($_POST['addition']);

if(
$_POST['addition']) fwrite($file$together ); 

(03-26-2012, 01:13)SuperNovaAO Wrote: also
PHP Code
  1. $add = $_POST['addition'] + ", ";
  2. echo $add; //output: 0; independently of the input.


Also I would scan for commas in the input to prevent your file getting fucked up.

what do you mean by it getting fucked up?
[Image: ScHmIdTy56789.png]
  Reply
#6
PHP Code:
<!-- coded by ScHmIdTy  -->
<?
php
$fn 
"globalban.txt"
$file fopen($fn"a+"); 
$size filesize($fn);
$togetheradd ", " htmlspecialchars($_POST['addition']);
$togetherclear ", " htmlspecialchars($_POST['clear']);
$clear str_replace($_POST['clear'],''fread($file,300));

if( 
$_POST['ban'] ) {
    
$file1 fopen($fn"a+"); 
    
fwrite($file$togetheradd ); 
} elseif( 
$_POST['unban'] ) {
    
$file2 fopen($fn"w+"); 
    
fwrite($file2$clear );
}
$text file_get_contents'globalban.txt' );
fclose($file);

?> 
<html>
    <body>
        Ban:
        <form action="<?=$PHP_SELF?>" method="post"> 
        <textarea><?=$text?></textarea><br/> 
        <input type="text" name="addition"/> 
        <input type="submit" name="ban"/> 
        </form>

        Un-Ban:
        <form action="<?=$PHP_SELF?>" method="post"> 
        <textarea><?=$text?></textarea><br/> 
        <input type="text" name="clear"/> 
        <input type="submit" name="unban"/> 
        </form>
    </body>
</html> 

I got it Wink
[Image: ScHmIdTy56789.png]
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Information [Tutorial] Making MORE glass in your form. Nekochan 27 10,872 03-22-2013, 22:04
Last Post: kokole
Information [Tutorial] Making a "Check on updates" form Nekochan 7 4,465 02-01-2012, 14:37
Last Post: Yamato
  [Tutorial] Making a login form OrangePL 12 5,775 02-01-2012, 11:22
Last Post: d0h!
  Help opening a form via button ? TheCodKingz10 10 5,775 11-24-2011, 11:58
Last Post: Rendflex

Forum Jump:


Users browsing this thread: 2 Guest(s)