I’m trying to send data from a html form to another drupal page.
The Form (in JavaScript):
var data = { // JS Object with data to send priceUnit: '131.97', priceTotal: '131.97', priceCount: '1', articleNumber: 'XYZ' }; // Form creation var form = document.createElement("form"); form.style.display = 'none'; // link to drupal site form.action = "../configurator/process_order"; form.method = "post"; form.target = "_blank"; // Create form Content from JS Object data for (var key in data) { var input = document.createElement("input"); input.name = key; input.value = data[key]; form.appendChild(input); } document.body.appendChild(form); form.submit();
On the other page, I am trying to access php $_POST
but there is no output:
<div> <?php echo $_POST['priceUnit']; ?> </div>
But, if I add var_dump($_POST);
in my module: configurator.module:
function configurator_process_order() { var_dump($_POST); $modulePath = drupal_get_path('module', 'configurator'); $content = file_get_contents($modulePath . "/Trader/PHPWebPages/processOrder.php"); return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)); }
I get the following output:
array (size=4) 'priceUnit' => string '131.97' (length=6) 'priceTotal' => string '131.97' (length=6) 'priceCount' => string '1' (length=1) 'articleNumber' => string 'XYZ' (length=3)
So the form has submitted it’s data but I cannot access it on my drupal page.
What am I doing wrong?
Sponsored by SupremePR