Pass bootstrap values to PHP


I have downloaded a template with bootstrap in which there is a FORM type part that consists of the following:

<div class="share-desc">
  <div class="share">
   <p>Number of units :</p><input type="number" class="text_box" type="text" value="1" min="1" />               
  <div class="button"><span><a href="#">Add to Cart</a></span></div>                    
  <div class="clear"></div>

To send the selected values and the product data I tried to do this:

<from action="carro/prueb1.php" method="POST">
   <div class="share-desc">
      <div class="share">
        <p>Numero de Unidades :</p><input type="number" class="text_box" type="text" value="1" min="1" id="num" />
      <div class="button" type="submit" name="btn"><span><a>Añadir al Carro</a></span></div>         
      <div class="clear"></div>

At the moment in PHP I have this:

  if ( !isset($_SESSION['btn'])){

       echo "<h2> Mensaje </h2>";
        echo "<h2>".$uni."</h2>";  

I want to alter the code of the bootstrap template as little as possible, but at the same time I need the values sent to work for me, something that I have not achieved at the moment. I have worked little with bootstrap, hence my question

What should I do to pass the values to PHP?

asked by Gabriel 02.11.2016 в 10:53

2 answers


To complement the response of Error404, the type attribute is not valid in the <div> tag, so it probably has no effect for the form submission.

See documentation for <div> in MDN: link

Ideally, you should use the <button> or <input type="submit">.


Keeping in mind that you do not want to modify the html, the only option you have is JavaScript, something like this could work:

// tu form no tiene ningún id o clase, asumiendo que es el primer form del documento
var form = document.forms[0];

// enviar el formulario al hacer clic en el primer elemento con la clase "button" 
form.getElementsByClassName("button")[0].addEventListener("click", function () {
answered by 02.11.2016 / 15:09

You have to indicate in your input the attribute name :

<input type="number" class="text_box" type="text" value="1" min="1" id="num" name="num" />

This way, when recovering the data, you can do $_POST['num'] .

answered by 02.11.2016 в 10:59