2

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

0

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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'];
?>

Comments

0

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.

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.