Reputation: 13
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
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
Reputation: 614
if you are getting Post in same page .. keep you action blank
Upvotes: 0
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