<textarea name="pageeditor" id="tbMsg" style="height:350px;width:100%;"></textarea>
is the code to my textarea.
It doesn't submit (wont set $_POST['pageeditor']) but it will if I do:
<textarea name="pageeditor" id="tbMsg" style="height:350px;width:100%;">TEXT HERE</textarea>
which doesn't make any sense to me. It doesn't submit any text I type in on the page, but will if I hard code it into the page.
any ideas?
I tried this and it seems to be displaying the textarea text that I enter.
<?php
echo "<pre>";
print_r($_POST);
echo $_POST['pageeditor'];
echo "</pre>";
?>
<form method="post">
<textarea name="pageeditor" id="tbMsg" style="height:350px;width:100%;"></textarea>
<button type="submit" name="form_submit"> Submit</button>
</form>
<p>
<?php
if(isset($_POST['submit']))
{
echo $_POST['textarea'];
}
?>
</p>
<form method="post">
<textarea name="textarea" cols="30" rows="10"></textarea>
<button type="submit" name="submit">Submit</button>
</form>
Related
So i have the following code for the aside which allows the user to search for other user(NOTE: i have left out the aside-tag here in order to make the code more readable):
<form action="index.php" method="POST">
<input id="search" type="text" placeholder="Search for Friends" name="search_name">
<input class="submit" type="submit" name="search-submit" value="Search">
</form>
After than i get the data from the database and display them in a variable whicht is called $output:
<?php
echo #$output;
?>
Ok so now when the user clicks on a name it should load the chatwindow in the aside instead of the search results. So the $output should be replaced with the chat window which has the following code:
<?php
if (isset($_POST['chat-submit'])) {
echo '<form method="POST" action="index.php" class="form-back">
<input class="back" type="submit" name="back" value="←Back">
</form>
<form>
<div class="chatwith"><h1><?php echo $username; echo ":"; ?></div>
<?php echo $finalstatus; ?>
<form action="index.php" method="POST" class="message-form">
<input class="message" type="text" placeholder="message" name="message">
<input class="submit" type="submit" name="message-submit" value="Send">
</form>';
}
?>
ok so both codes are working fine but when i click on one of the $outputs (and activate "chat-submit") than the old form from the search box is still there. How can i remove the old form so that only the chatwindows will be shown. Is there some kind "refresh only the aside"? If you have any questions please ask me.
If you set $refresh to 0 you dont need the if. Because it is always 0. Do like this:
<?php
if(isset($_POST['chat-submit'])) {
echo '//here goes the chat-form but this is too long for this comment. But its the same as above'; }
else {
echo $output;
}
?>
So it does work now this is the right solution from #Dieter Kräutl:
<?php
if(isset($_POST['chat-submit'])) {
echo '<form method="POST" action="index.php" class="form-back">
<input class="back" type="submit" name="back" value="←Back">
</form>
<form>
<div class="chatwith"><h1><?php echo $username; echo ":"; ?></div>
<?php echo $finalstatus; ?>
<form action="index.php" method="POST" class="message-form">
<input class="message" type="text" placeholder="message" name="message">
<input class="submit" type="submit" name="message-submit" value="Send">
</form>'; }
else {
echo $output;
}
?>
I have a text area where i can input text, after the form has been submitted the text from the first field goes to the second output field. Now I have the exact same things on the same page, so input field, submit and output field. What I want is when the either one of the submit buttons have been pressed, the output will stay and not clear out. Here is what I've done so far:
<head>
<title></title>
<meta charset="utf-8">
<?php
$inputText = $_GET['FirstText'];
$InputTextTwo = $_GET['SecondText'];
?>
</head>
<body>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="FirstText"></textarea>
<br>
<input type="submit" name="submit_firstField" value="FirstField">
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfFirst"><?php echo $inputText; ?></textarea>
</form>
<hr/>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="SecondText"></textarea>
<br>
<input type="submit" name="submit_SecondField" value="SecondField">
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfSecond"><?php echo $InputTextTwo; ?></textarea>
</form>
</body>
As you can see, when the first submit has been done and I want to do the second one, the first output disappears, and vice versa.
I have solved your problem.
The main reason is the two textareas now used different Form.
So Only one textarea value can submit at once.
I added temp hidden-input field inside each form and run the code.
And It's working well now. Please check them.
Tian Yang
<html>
<head>
<title></title>
<meta charset="utf-8">
<?php
$inputText = 'asdf';
$InputTextTwo = 'bbbb';
if(isset($_GET['FirstText'])){
$inputText = $_GET['FirstText'];
$InputTextTwo = $_GET['temp'];
}
if(isset($_GET['SecondText'])){
$InputTextTwo = $_GET['SecondText'];
$inputText = $_GET['temp'];
}
?>
</head>
<body>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="FirstText"></textarea>
<br>
<input type="submit" name="submit_firstField" value="FirstField">
<input type="hidden" name="temp" value ="<?php echo $InputTextTwo; ?>" />
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfFirst"><?php echo $inputText; ?></textarea>
</form>
<hr/>
<form action="#" method="GET">
<textarea cols="50" rows="2" name="SecondText"></textarea>
<br>
<input type="submit" name="submit_SecondField" value="SecondField">
<input type="hidden" name="temp" value ="<?php echo $inputText; ?>" />
<br>
<textarea disabled="yes" cols="50" rows="2" name="SecondOfSecond"><?php echo $InputTextTwo; ?></textarea>
</form>
</body>
</html>
I'm constructing my website and I wanted to know if it was possible to write something in html's 'textarea' on one page then take that text and print it out using PHP on a new webpage that saves the text last entered.
I just wanted to know how you would go about the process. At the moment I have created a HTML form with three text boxes that I would like to be displayed once the submit button is pressed.
<div id="createmeeting">
<form method="POST">
<b>Meeting Title:</b>
<textarea name="title" cols="50" rows="2"></textarea>
<b>Date and Time:</b>
<textarea name="date" cols="50" rows="2"></textarea>
<b>Details:</b>
<textarea name="details" cols="50" rows="20"></textarea>
<input type="submit" name="go" value="Save Changes!">
First you need an action attribute in your form tag, that points to the php file that should process the form data:
<div id="createmeeting">
<form method="POST" action="targetfile.php">
<b>Meeting Title:</b>
<textarea name="title" cols="50" rows="2"></textarea>
<b>Date and Time:</b>
<textarea name="date" cols="50" rows="2"></textarea>
<b>Details:</b>
<textarea name="details" cols="50" rows="20"></textarea>
<input type="submit" name="go" value="Save Changes!">
</form>
</div>
and in targetfile.php
<?php
/* ensure that the data has been posted */
if($_SERVER['REQUEST_METHOD'] == 'POST') {
/* read the data from $_POST */
$title = $_POST['title'];
$date= $_POST['date'];
$details= $_POST['details'];
/* here you can do whatever you want with the data, output it, store it in a database ... */
echo "Title: ".$title."<br>";
echo "Date: ".$date."<br>";
echo "Details: ".$details;
}
?>
Here's my code:
<?php
$view="Mickey Mouse";
?>
<script type="text/javascript">
function doOne(){
document.getElementById("xyz").submit();
}
function doTwo(){
document.getElementById("xyz").submit();
}
</script>
<form class="xyz" id="xyz" method='POST' accept-charset="UTF-8" action='index.php'>
<textarea rows="4" cols="60" name='article' id='article' WRAP=SOFT>
<?php echo $view;?>
</textarea>
<p>
<button type="button" name='do1' id='do1' value="do 1" onclick="doOne()">do 1</button>
<button type="button" name='do2' id='do2' value="do 2" onclick="doTwo()">do 2</button>
</p>
</form>
<?php
var_dump("POST :",$_POST);
?>
When I run it, the form displays [tab][tab]Mickey Mouse[tab] instead of simply Mickey Mouse. Why is that?
Close the space around < ? php echo $view; ?>
<textarea rows="4" cols="60" name='article' id='article' WRAP=SOFT><?php echo $view;?></textarea>
The textarea has no way of knowing whether those newlines and spaces are supposed to be part of the textarea content, so of course it includes them.
I am new to php and I need some help.
I have two sites. And I want to display text box from my edit.php on index.php.
<form method="post">
<textarea name="content" cols="40" rows="5">
Enter your comments here...
</textarea><br>
<input type="submit" value="Submit" />
</form>
<?php
$content = $_POST["content"];?>
How do I transfer variable $content to my index page?
To address your comments. (Don't down rank me... his original question was not precise).
// on your edit page
<form method="post">
<textarea name="content"></textarea>
<input type="submit" />
</form>
// when you submit your edit page
$filename = '/mytextarea.txt';
$content = file_put_contents( $filename, $_POST['content'] );
// on your index page
$filename = '/mytextarea.txt';
$content = file_get_contents($filename);
if( ! empty( $content ) ){
echo '<div>'.$content.'</div>';
}
From edit you want to make sure your action points to index.php
edit.php
<form method="post" action="index.php">
<textarea name="myTextBox" cols="40" rows="5"></textarea>
<input type="submit" value="Submit" />
</form>
In index.php, you can access the variable with $_POST["myTextBox"], this can be outputted as text or as a value in the example below. Be sure to use htmlentities when including the value back with a form field, this will prevent "injection hacking".
index.php
<?php echo $_POST["myTextBox"] ?>
<form method="post" action="index.php">
<textarea name="myTextBox" cols="40" rows="5"><?php echo htmlentities($_POST["myTextBox"]); ?></textarea>
<input type="submit" value="Submit" />
</form>
Well, just set the action on the form to the page you want it to post to - example:
Random Page:
<form method="post" action="/index.php">
<textarea name="content" cols="40" rows="5">
Enter your comments here...
</textarea><br>
<input type="submit" value="Submit" />
</form>
Index.php:
if(isset($_POST['content']) && !empty($_POST['content'])){
echo htmlspecialchars($_POST['content']);
}
At least I think this is what you are asking?
If you are echoing a random textbox to a page, make sure to sanitize it using htmlspecialchars()
Try to action your form to your index.php :
<form method="post" action="/index.php">
</form>
With that, once you submit your form, your page index.php will be loaded, with values of your form in $_POST.
// on your edit page
<form method="post" action="index.php">
<textarea name="content"></textarea>
<input type="submit" />
</form>
// on your index page
if( $_SERVER['REQUEST_METHOD'] == 'POST' ){ // This will prevent the textarea from
// being shown unless some form posted to this page
echo '<form method="post">
<textarea name="content">'.$_POST['content'].'</textarea>
<input type="submit" />
</form>';
// If it's not set or it's empty, then it just won't show anything....
// you don't need to check for that unless you want to set a value when it is empty
}
Just change your form to post to the second site instead of to itself, then echo the $_POST['content'] on your index.php page
www.firstsite.com/edit.php
<form action="www.secondsite.com/index.php" method="post">
<ul>
<li>
<textarea name="content" cols="40" rows="5">Enter your comments here...</textarea>
</li>
<li class="submit">
<input type="submit" value="Submit" />
</li>
</ul>
</form>
www.secondsite.com/index.php
<?php echo $_POST['content']; ?>