user2965726
user2965726

Reputation:

PHP with HTML textarea

I am quite new to PHP/HTML all this kind of stuff so sorry if this is an easy question!

Is there a way to read the contents of an HTML text area and pass it into a .php file?

Or even just reading the contents of the text area into a variable would do.

Thanks

Upvotes: 2

Views: 17935

Answers (4)

Zeeshan
Zeeshan

Reputation: 886

You can Post the form and can access the variable of the form with $_POST['myObj']; Looking at the $_POST and fetching the value from the post through object name.

Here, "myObj" is an example object name.

Upvotes: 0

Zahidul Hossein Ripon
Zahidul Hossein Ripon

Reputation: 672

you need to submit the form to get the textarea value. Or you can use Jquery to get the textarea content

Upvotes: -1

user2959229
user2959229

Reputation: 1355

Give your textarea a name and post it to a PHP script with a form. The data from the textarea will be available in the $_POST['textareaName'] variable.

HTML

<form action="page.php" method="post">
    <textarea name="myTextarea"></textarea>
    <input type="submit" value="go" />
</form>

PHP

<?php
echo $_POST['myTextarea'];
?>

Upvotes: 3

DontVoteMeDown
DontVoteMeDown

Reputation: 21475

You can achieve that with a basic form:

index.php:

<?php

if ($_POST) // If form was submited...
{
    $text = $_POST["mytextarea"]; // Get it into a variable
    echo "<h1>$text</h1>"; // Print it!
}

?>
<form method="post">
    <textarea name="mytextarea"></textarea>
    <input type="submit" value="Go!" />
</form>

And this can be done whatever input element you want e.g: inputs type text, password, checkbox, radio or a select or even and fresh HTML5 input type.

Upvotes: 3

Related Questions