News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

posting

Started by Thunderace, May 31, 2005, 03:49:21 PM

Previous topic - Next topic

Thunderace

When posting in you get a textarea that is then "posted" and in the case of SMF posts to a DB.

In my case I'm using a textarea that will then simply write to a text file.

What is the <form> I should use if I want a <form> above the textarea

and a "submit" button under the textarea and write to the variable $somecontent?

Trekkie101

#1
You mean like this

post.php
<?php
echo'<form action="process.php" method="post">
<input name="message" type="text" />
<input type="submit" />
</form>'
?>


The word message forms my variable $message

process.php
<?php

$filename 
'test.txt';
$somecontent $message;

$handle fopen($filename'a');

fwrite($handle$somecontent);

fclose($handle);

echo 
"Message Successfully Posted";

?>


Like that?
That was what I made last night, playing around with php, then I read it by

view.php
<?php
$filename 
'test.txt';
$fp fopen($filename"r");
$YEAH fread($fpfilesize($filename));
fclose($fp);
echo 
$YEAH;
?>


But I needed the file test.txt premade.

Sorry if im babling on.


Thunderace

No no it's helping m8.

How do I pass the form variable to a new file action="../newfile.php"

?

Trekkie101

Do you mean like,

Post -> Proccess -> Process2
I dont know, Ive just took it Post -> process using the method="post" thing and then took the variable in process.php and wrote it to the file using process.php as it had already defined the variable.

Thunderace

<form action="../myfile.php" method="post">
<input name="contents" type="text" />
      <textarea id='maintext'>
Place your page contents and keywords here.
</textarea>
<script>replaceTextarea(
            'maintext'                  //textarea id
            , '100%'                   //width
            , '200px'                   //height
            ,'/rich-textarea-53'        //html directory
            ,'/rich-textarea-53.css'                //style sheet file
            )</script>
            <input type="submit"/>
            </form>

$contents is not passing to "myfile.php"  as a variable it's empty

Trekkie101

<form action="../process.php" method="post">
<input name="contents" type="text" />
      <textarea id='maintext'>
Place your page contents and keywords here.
</textarea>
<script>replaceTextarea(
            'maintext'                  //textarea id
            , '100%'                   //width
            , '200px'                   //height
            ,'/rich-textarea-53'        //html directory
            ,'/rich-textarea-53.css'                //style sheet file
            )</script>
<input type="submit"/>
</form>


<?php
$filename 
'myfile.php';
$somecontent $contents;

$handle fopen($filename'a');

fwrite($handle$somecontent);

fclose($handle);

echo 
"Message Successfully Posted";

?>


myfile.php


That uses the form on the first bit, then passes it to process which then writes the data to myfile.php

Is that it?


Trekkie101

Ah right, sorry about that.

method="post">

That should create the variable you specify <input name="contents"

and when called as $contents it should work.


Sorry im kinda new to php.

Thunderace

<script language="JavaScript" type="text/javascript" src="/rich-textarea-53/rich-textarea-53.js"></script>
<form action="testwrite.php" method="post">
<input name="contents" />
      <textarea id='contents'>
Place your page contents and keywords here.
</textarea>
           <input type="submit"/>
            </form>
<script>replaceTextarea(
            'contents'                  //textarea id
            , '100%'                   //width
            , '200px'                   //height
            ,'/devzone/rich-textarea-53'        //html directory
            ,'/devzone/rich-textarea-53.css'                //style sheet file
            )</script>


This is not passing the variable $contents to testwrite.php

[Unknown]

Try $_POST['contents'].

-[Unknown]

Thunderace

Sorry to be thick, but where?

It is like ..

<form (plus whatever)>
<textarea id='contents'>
This is what I want to become the variable (text/html only)
</textarea>
<input (plus whatever)>
</form>

[Unknown]

I meant when accessing it.  I would guess this is register_globals being off.

-[Unknown]


[Unknown]

Instead of this:

<?php
$filename 
'myfile.php';
$somecontent $contents;

$handle fopen($filename'a');

fwrite($handle$somecontent);

fclose($handle);

echo 
"Message Successfully Posted";

?>


Use:

<?php
$filename 
'myfile.php';
$somecontent $_POST['contents'];

$handle fopen($filename'a');

fwrite($handle$somecontent);

fclose($handle);

echo 
"Message Successfully Posted";

?>


-[Unknown]

Thunderace

Thanks [unknown]

This works ..

<script language="JavaScript" type="text/javascript" src="/devzone/rich-textarea-53/rich-textarea-53.js"></script>
<form action ="../devzone/testwrite.php" method = "post">
<b>Enter text</b>
<input type ="text" name = "contents">
<p />
<input type = "submit" value = "SEND!">


However it only passes one line. How do i get it to pass text/html with virtually no limit?


Thunderace

New problem  :D

Posting text/html is fine, however when posting a URL link it adds "\" as follows: -

<a href=\"http://www.mysite.com/index.php\">home</a>


Thunderace

Ok I've now got mulltiple html <textarea>'s within a <form>

each with it's own id=

I want to send all the <textarea>'s as one "submit"

and read them in the next script as $_POST["myvariable"];

Help appreciated please  :D

[Unknown]

You can't do that.  But, if you name them all "something[]" then you can do:

$myvar = implode('', $_POST['something']);

-[Unknown]

Advertisement: