I've got a JavaScript function, that as an array, and a HTML form that sends data to a PHP page to later send it by email. But I would also need to send the result of the JavaScript function on the form to the php page. Is this possible?
I'm currently trying the following way, but with no results:
HTML page and script :
function showcartitems() {
var showcart = paypal.minicart.cart.items();
}
<form action="teste4.php" method="post" class="creditly-card-form agileinfo_form" onsubmit="showcartitems()">
<section class="creditly-wrapper wthree, w3_agileits_wrapper">
<div class="information-wrapper">
<div class="first-row form-group">
<div class="controls">
<label class="control-label">Nome Completo: </label>
<input class="billing-address-name form-control" type="text" name="name" placeholder="Nome Completo">
<input type="hidden" name="cart" value="showcart" />
</div>
<div class="w3_agileits_card_number_grids">
<div class="w3_agileits_card_number_grid_left">
<div class="controls">
<label class="control-label">Numero de telemóvel:</label>
<input class="form-control" type="text" name="mobile" placeholder="Numero de telemóvel">
</div>
</div>
<div class="w3_agileits_card_number_grid_left">
<div class="controls">
<label class="control-label">Email:</label>
<input class="form-control" type="text" name="email" placeholder="Email">
</div>
</div>
<div class="w3_agileits_card_number_grid_right">
<div class="controls">
<label class="control-label">Rua: </label>
<input class="form-control" type="text" name="rua" placeholder="Rua">
</div>
</div>
<div class="clear"> </div>
</div>
<div class="controls">
<label class="control-label">Cidade: </label>
<input class="form-control" type="text" name="cidade" placeholder="Cidade">
</div>
<div class="controls">
<label class="control-label">Método de pagamento: </label>
<select name="pagamento">
<option>MBWay</option>
<option>Transferência Bancária</option>
<option>Multibanco (apenas para entregas ao domicílio)</option>
</select>
</div>
</div>
<button class="submit check_out">Verificar disponibilidade!</button>
</div>
</section>
</form>
The PHP page is still quite simple, just checking if the variables are coming correctly, they all are, except the value of the javascript function:
echo $_POST['name'];
echo $_POST['mobile'];
echo $_POST['email'];
echo $_POST['rua'];
echo $_POST['cidade'];
echo $_POST['pagamento'];
echo $_POST['showcart'];
?>
Am I doing something wrong? Is there a better way to do this, or is it just impossible?
EDIT 1: Following @epascarello suggestion, I've managed to get the value into the PHP side, which is returning the following:
[{"_data":{"cmd":"_cart","add":"1","item_name":"FILA 1010302","item_image":"images/1010302-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":2,"href":"http://teste/index.html#5"},"_options":[],"_discount":100,"_amount":99,"_total":98,"_eventCache":{"change":[[null,null]]}},{"_data":{"cmd":"_cart","add":"1","item_name":"FILA 1010575","item_image":"images/1010575-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":1,"href":"http://teste/index.html#5"},"_options":[],"_discount":50,"_amount":99,"_total":49,"_eventCache":{"change":[[null,null]]}},{"_data":{"cmd":"_cart","add":"1","item_name":"FILA 1010707","item_image":"images/1010707-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":1,"href":"http://teste/index.html#5"},"_options":[],"_discount":50,"_amount":99,"_total":49,"_eventCache":{"change":[[null,null]]}},{"_data":{"cmd":"_cart","add":"1","item_name":"FILA SCM00514","item_image":"images/scm00514-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":1,"href":"http://teste/index.html#5"},"_options":[],"_discount":50,"_amount":99,"_total":49,"_eventCache":{"change":[[null,null]]}}]
I've tried several approaches with json_decode, but I'm not getting the result I seek.
I would like to split that array into, for example:
item_name=x;
item_image=x;
quantity=x;
Can someone pin point me into the right direction? Sorry for asking this, I'm new in this languages and despite my research I did not manage to get to a solution on my own.
Thank you in advance.