kusanagi
kusanagi

Reputation: 14624

php get value from textarea

how can i get value from field textarea. i want to detail- i need to parse html page and get value from field textarea not call something like $_POST["textarea"]

Upvotes: 1

Views: 5994

Answers (3)

Jump46
Jump46

Reputation: 1

This didn't work for me:

// dom
$nodes = $dom->getElementsByTagName('textarea');
$node1 = $nodes->item(0);

I used $node1 = $nodes->item(0)->nodeValue; since the class DOMElement inherit the DOMNode properties as you can see here.

Upvotes: 0

Ben Petersen
Ben Petersen

Reputation: 506

It's much simpler, but this should work (assuming you print $display later on)

$display .= "<textarea name='notes' rows='3' cols='30'>".$notes."</textarea><br />";

Upvotes: 0

Alex
Alex

Reputation: 6470

Option 1

Best way for parsing like this is to use DOM, http://www.php.net/manual/en/book.dom.php After you load your page into the DOM, you can use getElementById('textarea_id'), php docs are here. If your text area has ID or getElementsByTagName('textarea'), but in this case you will get NodeList. So it will look something like this:

// dom
$nodes = $dom->getElementsByTagName('textarea');
$node1 = $nodes->item(0);


Option 2

Another option is to get the page as string and use regular expression to match your textbox and get info out of it. I found this class in google, it is HTML Form Parser - http://www.alexandruion.com/html-form-parser

Upvotes: 3

Related Questions