Assign a textarea value to a variable
Moderator: General Moderators
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
Assign a textarea value to a variable
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 ?
How can I pass the value of a textarea to a variable so that I can send it via post ?
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
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
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
It doesduzchip wrote: I hope this makes sense
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>$_POST['status'] and $_POST['comment']
aerodromoi
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
Here's my code I need it in, It does'nt seems to work in :
This is where the textarea is created
And this is the other script (addtestwrite.php) where I whant to passe the value of the textbox:
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);
?>- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Sorry, but this piece of code is not exactly neat...Peuplarchie wrote:Here's my code I need it in, It does'nt seems to work in :
This is where the textarea is created
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
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
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>- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
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>- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
addtest11write
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);
?>- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Re: addtest11write
Because your trying to get posted data via get.Peuplarchie wrote:still only giving me te variable name...Code: Select all
$new_line = "\r". $_GET['codes']."\n\r";
aerodromoi
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
Code: Select all
$new_line = "\r". $_POST['codes']."\n\r";