Bryan
Bryan

Reputation: 13

Textarea name given back undefined

Getting back $message is undefined. I've tried switching $_POST['message'] to $_POST['send']. it works, but for some reason it won't work with the text-area. I even tried to switch the button type from button to submit. It didn't help. This mistake's given me a real headache.

<?php
$message = $_POST['message'];
?>

<form action="chat.php" method="POST">
<textarea name="message" id="type" placeholder="Type your message"></textarea>
<input name="send" id="send" type="button" value="send" onclick="sendmsg()"/>
</form>

Upvotes: 1

Views: 190

Answers (3)

user4523269
user4523269

Reputation:

Do one thing:

print_r($_POST); die;

And check whats coming from form . It will help you to find out the problem.

Upvotes: 1

Tariq hussain
Tariq hussain

Reputation: 614

if you are getting Post in same page .. keep you action blank

Upvotes: 0

J.K.A.
J.K.A.

Reputation: 7404

I've remove sendmessage() and replace button type to submit. Keeping it simple.

<?php
if(isset($_POST['send'])){
echo "<pre>";
print_r($_POST);
$message = $_POST['message'];
}
?>

<form action="" method="POST">
<textarea name="message" id="msgtype" placeholder="Type your message"></textarea>
<input name="send" id="send" type="submit"/>
</form>

Try it. Hope it'll work.

Upvotes: 0

Related Questions