Page 1 of 2
Assign a textarea value to a variable
Posted: Sat May 13, 2006 2:31 am
by Peuplarchie
Good day to you all !
How can I pass the value of a textarea to a variable so that I can send it via post ?
Posted: Sat May 13, 2006 2:35 am
by duzchip
You just use the textareas name as a variable.
If you name the textarea "donkeyshoe" after you press the send-button there will be a variable named $donkeyshoe.
So if you use the post-method in the form-tag it's just to do a $_POST['donkeyshoe'] in the file you're sent to after pressing the send-button om the form. I hope this makes sense

Posted: Sat May 13, 2006 3:29 am
by aerodromoi
duzchip wrote:
I hope this makes sense

It does
Code: Select all
<form method="post" action="index.php">
<textarea name="comment" rows="6" cols="6" style="width: 200px; height: 100px"></textarea>
<input type="submit" name="status" value="submitted" />
</form>
This form would give you two variables: status and comment
$_POST['status'] and $_POST['comment']
aerodromoi
Posted: Sat May 13, 2006 12:01 pm
by Peuplarchie
Here's my code I need it in, It does'nt seems to work in :
This is where the textarea is created
Code: Select all
<?php
if (!isset($_POST[submit]))
{
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
Nom : <input type="text" name="nom"><br>
Date d'affichage : <input type="text" name="affiche"><br>
Courriel : <input type="text" name="courriel"><br>
Évènement : <input type="text" name="evenement"><br>
Date de l' évènement : <input type="text" name="date"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
}else{
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<style><!--
a:hover{color:"yellow"; }
a:hover{font-size:9px}
.red {
font-size: 9px;
font-family: verdana,Arial, Helvetica, sans-serif;
text-decoration: none;
color: red;}
.white {
font-size: 9px;
font-family: Verdana,Arial, Helvetica, sans-serif;
text-decoration: none;
color: white;}
.black {
font-size: 9px;
font-family: verdana,Arial, Helvetica, sans-serif;
text-decoration: none;
color:black;}
.black2 {
font-size: 9px;
font-family: verdana,Arial, Helvetica, sans-serif;
text-decoration: none;
color:black;}
.gray {
font-size: 13px;
font-family: verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
color: gray;}
.dgray {
font-size: 9px;
font-family: verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
color: darkgray;}
.yellow {
font-size: 9px;
font-family: verdana,Arial, Helvetica, sans-serif;
text-decoration: none;
color:yellow;}
.beige {
font-size: 9px;
font-family: verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
color: 999966;}
.blue {
font-size: 9px;
font-family: verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
color: 003366;}
//-->
</style>
</head>
<body bgcolor=black text="white" vlink="black" link="black" alink="black" >
<br><br>
<b>Voici votre résultat <?php echo $_POST['nom']; ?> :</b><hr>
<table border=0 align="center" cellspacing=1 cellpading=0 >
<tr><td bgcolor="#003366" class="white" align="center"><table border=0 align="center" cellspacing=1 cellpading=0 >
<tr><td bgcolor="#000000" class="white" align="left" width=500>
Nom : <?php echo $_POST['nom']; ?><br>
Date d'affichage : <?php echo $_POST['affiche']; ?><br>
Courriel : <?php echo $_POST['courriel']; ?><br><br>
Évènement : <?php echo $_POST['evenement']; ?><br>
Date de l' evenement : <?php echo $_POST['date']; ?>
</td><tr>
</table>
</table>
<br><br>
<hr>
<form action='addtest11write.php' method="post" name="codetest">
<center>
<textarea cols="80" rows="20" wrap="off" name="coding" >
<table border=0 align="center" cellspacing=1 cellpading=0 >
<tr><td bgcolor="#003366" class="white" align="center"><table border=0 align="center" cellspacing=1 cellpading=0 >
<tr><td bgcolor="#000000" class="white" align="left" width=500>
Nom : <?php echo $_POST['nom']; ?><br>
Date d'affichage : <?php echo $_POST['affiche']; ?><br>
Courriel : <?php echo $_POST['courriel']; ?><br><br>
Évenement : <?php echo $_POST['evenement']; ?><br>
Date de l' evenement : <?php echo $_POST['date']; ?><br>
</td><tr>
</table>
</table>
</textarea>
</center>
<input type="submit" name="confirm" value="Confirm">
</form>
</body>
</html>
<?php
}
?>
And this is the other script (addtestwrite.php) where I whant to passe the value of the textbox:
Code: Select all
<?php
// your new data + newline
$new_line = $_post['coding']."\r\n";
// the filepath
$file = 'aaatest.html';
// the old data as array
$old_lines = file($file);
// add new line to beginning of array
array_unshift($old_lines,$new_line);
// make string out of array
$new_content = join('',$old_lines);
$fp = fopen($file,'w');
// write string to file
$write = fwrite($fp, $new_content);
fclose($fp);
?>
Posted: Sat May 13, 2006 12:46 pm
by aerodromoi
Peuplarchie wrote:Here's my code I need it in, It does'nt seems to work in :
This is where the textarea is created
Sorry, but this piece of code is not exactly neat...
A few general remarks:
1. please use $_POST['submit'] instead of $_POST[submit]
2. use quotation marks where necessary - eg. cellspacing="1"
3. the stylesheet is irrelevant here - it only takes up space
4. instead of <?php $_SERVER['PHP_SELF']; ?> you should use <?php echo $_SERVER['PHP_SELF']; ?>
As to your question: If you want to post the variables to addtest11write.php, why do you call the file addtestwrite.php?
Bonne chance,
aerodromoi
Posted: Sat May 13, 2006 12:53 pm
by Peuplarchie
That why we are not alone in the worl, to help each other like you just did !..again
Thanks !
Posted: Sat May 13, 2006 12:56 pm
by aerodromoi
Peuplarchie wrote:That why we are not alone in the worl, to help each other like you just did !..again
Thanks !
So it was just the filename... It happens to everyone once in a while
aerodromoi
Posted: Sat May 13, 2006 1:07 pm
by Peuplarchie
aerodromoi wrote:
As to your question: If you want to post the variables to addtest11write.php, why do you call the file addtestwrite.php?
i
So in my action I should use what ?
Posted: Sat May 13, 2006 1:24 pm
by Peuplarchie
yearh your're right, it was the file name.
It still dont work I can only pass the variable name not the value of it.
Posted: Sat May 13, 2006 1:27 pm
by Peuplarchie
Code: Select all
<form action="addtest11write.php?coding=$codes" method="post" name="codetest">
<center>
<textarea cols="80" rows="20" wrap="off" name="codes" >
<table border="0" align="center" cellspacing="1" cellpading="0" >
<tr><td bgcolor="#003366" class="white" align="center"><table border="0" align="center" cellspacing="1" cellpading="0" >
<tr><td bgcolor="#000000" class="white" align="left" width="500">
Nom : <?php echo $_POST['nom']; ?><br>
Date d'affichage : <?php echo $_POST['affiche']; ?><br>
Courriel : <?php echo $_POST['courriel']; ?><br><br>
Évenement : <?php echo $_POST['evenement']; ?><br>
Date de l' evenement : <?php echo $_POST['date']; ?><br>
</td><tr>
</table>
</table>
</textarea>
</center>
<input type="submit" name="confirm" value="Confirm">
</form>
</body>
</html>
Posted: Sat May 13, 2006 1:50 pm
by aerodromoi
Peuplarchie wrote:yearh your're right, it was the file name.
It still dont work I can only pass the variable name not the value of it.
According to addtestwrite.php you're looking for a variable called "coding", but the name of the textarea is "codes".
aerodromoi
Posted: Sat May 13, 2006 1:58 pm
by Peuplarchie
Code: Select all
<form action="addtest11write.php?codes=codesource" method="post" name="codetest">
<center>
<textarea cols="80" rows="20" wrap="off" name="codesource" >
<table border="0" align="center" cellspacing="1" cellpading="0" >
<tr><td bgcolor="#003366" class="white" align="center"><table border="0" align="center" cellspacing="1" cellpading="0" >
<tr><td bgcolor="#000000" class="white" align="left" width="500">
Nom : <?php echo $_POST['nom']; ?><br>
Date d'affichage : <?php echo $_POST['affiche']; ?><br>
Courriel : <?php echo $_POST['courriel']; ?><br><br>
Évenement : <?php echo $_POST['evenement']; ?><br>
Date de l' evenement : <?php echo $_POST['date']; ?><br>
</td><tr>
</table>
</table>
</textarea>
</center>
addtest11write
Posted: Sat May 13, 2006 2:00 pm
by Peuplarchie
Code: Select all
<?php
// your new data + newline
$new_line = "\r". $_GET['codes']."\n\r";
// the filepath
$file = 'aaatest.html';
// the old data as array
$old_lines = file($file);
// add new line to beginning of array
array_unshift($old_lines,$new_line);
// make string out of array
$new_content = join('',$old_lines);
$fp = fopen($file,'w');
// write string to file
$write = fwrite($fp, $new_content);
fclose($fp);
?>
still only giving me te variable name...
Re: addtest11write
Posted: Sat May 13, 2006 2:13 pm
by aerodromoi
Peuplarchie wrote:Code: Select all
$new_line = "\r". $_GET['codes']."\n\r";
still only giving me te variable name...
Because your trying to get
posted data via get.
aerodromoi
Posted: Sat May 13, 2006 2:26 pm
by Peuplarchie
Code: Select all
$new_line = "\r". $_POST['codes']."\n\r";
and it's still dont wok mmmmmm what could it be ?