Xejo
Xejo

Reputation: 191

Grabbing the <textarea> value in php (HTML form)

I've got a simple HTML form where I switched from normal/traditional text fields to the textarea ones.

Within my form i have...

<form name="wreckAppForm" action="application2.php" method="post" onsubmit="return validateForm()">
    <textarea name="favSpec" form="wreckAppForm" rows="4" cols="100"></textarea>
...

Then, in application2.php I try to grab the information using...

$app_favSpec = $_POST["favSpec"];

But there is never anything in the value. I'm clearly missing something.

I've looked into several other "solutions" on SO and other sites. I've also read the W3Schools info on TEXTAREA along with other documentation.

I'm using the value (if I can ever get it) in a long concatenated string to eventually be written to a file.

Any tips would be greatly appreciated.

Upvotes: 0

Views: 133

Answers (2)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

My browser crashed just as soon as I was going to hit the "Post your Answer" button (a late answer), so after taking the time of typing all this out and testing, I'm submitting it anyway.

That's because of the form="wreckAppForm" in your textarea; remove it.

(Tested)

<?php

if(isset($_POST['submit'])){

    $app_favSpec = $_POST["favSpec"];
    echo $app_favSpec;

}

?>

<form name="wreckAppForm" action="" method="post" >
    <textarea name="favSpec" rows="4" cols="100"></textarea>

<input type="submit" name="submit" value="Submit">
</form>

Upvotes: 0

Joseph
Joseph

Reputation: 5160

Add:

id="wreckAppForm"

to your form element. The form element needs to have "wreckAppForm" in the ID for the textelement's form="wreckAppForm" to be valid.

Check out the doc for more info. I'd also stay away from W3Schools, too.

Upvotes: 3

Related Questions