How would I send information from a form to a block of PHP code and then back to a text area? I can not find this answer.
-
Your question is very very basic. My suggestion would be to follow this tutorial : net.tutsplus.com/articles/news/diving-into-php It'll be really helpfulJohnP– JohnP2011-04-30 06:29:03 +00:00Commented Apr 30, 2011 at 6:29
-
@JohnP I know but what I am trying to do is display my result in a text box but all the basic tutorials I had read or went with really did not displayed that they just say echo "something to document";AlThePal78– AlThePal782011-04-30 06:34:06 +00:00Commented Apr 30, 2011 at 6:34
3 Answers
To print out the text you entered in the textfield on the next request would look like this assuming you render the same page (i.e. myform.php):
<?php
$fieldValue = htmlentities($_POST['myfield']);
?>
<form action="myform.php" method="post">
<label for="myfield">Your textfield:</label>
<input type="text" name="myfield" id="myfield" value="<?php echo $fieldValue; ?>" />
</form>
4 Comments
A very basic example.
Assuming you have a PHP file named index.php
<?php
$val = 'Nothing in POST';
if (!empty($_POST)) { //$_POST is where stuff posted from the FORM is saved
$val = isset($_POST['text']) ? $_POST['text'] : '';//you're looking for the data with key text which is the name of your textarea element
$val = 'Got something from POST : ' . $val;
}
?>
<form action='index.php' method='post'>
<textarea name='text'><?php echo $val ?></textarea>
</form>
Have a look at this tutorial for the basics : http://net.tutsplus.com/articles/news/diving-into-php/
2 Comments
use ajax!(and use jquery for that ajax!)
suppose you have this html :
<input type="text" id="input">
<textarea id="result"></textarea>
than the script should be:
$('#input').keypress(function(e){
if(e.wich != 13)//not enter
return;
$.get(your_php_file.php,{param1:val1,param2:val2},function(result){
$('#result').val(result);
});
});
when you hit enter on the input field,the ajax function is being called that requests the file your_php_file.php?param1=val1¶m2=val2. With the php's result, the callback function is being called which updates your textarea