$ _POST array is empty

I have this code:

<div id="messageDiv">
<form>
<textarea name="message" rows="10" cols="20" id="message"></textarea></textarea>
<br /><br />
<input type="submit" value="Send" onClick="return sendmail()">
<input type="reset" value="Reset" name='reset'>
</form>
</div>

then I have my JS:

function sendmail()
{
  var mail = document.getElementById('message').value;
  window.location.href = "http://www.rainbowcode.net/apps_dev.php/profiles/mail?id="+mailid;
  return false;
}

when I alert(mail), I get the correct value, but when I get to my new page through window.location.href, I want to access this value ... my form is a "message" when I do print_r($_POST['message'])I get an empty array. Please, help?

+3
source share
4 answers

You have an error in your html that may affect it

<textarea name="message" rows="10" cols="20" id="message"></textarea></textarea>

it should be

<textarea name="message" rows="10" cols="20" id="message"></textarea>

In addition, this is not how the mail form is created. the mail sending function does not help at all

<form method='post' action='http://www.rainbowcode.net/apps_dev.php/profiles/mail'>
   <textarea name="message" rows="10" cols="20" id="message"></textarea>
   <br /><br />
   <input type="submit" value="Send">
   <input type="reset" value="Reset" name='reset'>
</form>

This should work

UPDATE:

, , . , :

<input name='mailid' type='hidden' value='somevalue' />
0

window.location.href, , ( , , URL-). , document.MyForm.submit();

EDIT: , <form>, . /, JS + post + action URL-.

+7

form post:

HTML- :

<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">



function sendmail()
{
  var mail = document.getElementById('message').value;
  window.location.href = "http://www.rainbowcode.net/apps_dev.php/profiles/mail?id="+mailid;
  return false;
}

mailid? , print_r($_POST['message']) , JavaScript? print_r($_GET['id']).

0

It is obvious. The popup that you open does not contain the same query variables as the "parent" page that opens it. This is a new HTTP request.

Data transfer between the "parent" window and the popup window ( $_SESSION, http://hr.php.net/manual/en/reserved.variables.session.php ).

0
source

All Articles