V
V
Vladimir Mazepa2015-11-03 17:28:39
PHP
Vladimir Mazepa, 2015-11-03 17:28:39

How to pass an additional field - the price of the product?

There is a quick form for purchasing goods, a small script is connected to the standard "buy \ add to cart" form of the prestashop engine. It is necessary to transfer an additional 1 more field - the price of the goods.
Here is the actual code:

<form action="/themes/default-bootstrap/modules/blockcart/ju_fast.php" method="post" onsubmit="return (ValidPhone())">
               		<div class="layer_cart_product_info">
                	    <span id="layer_cart_product_title" class="product-name"></span>
                	    <span id="layer_cart_product_attributes"></span>
            <input name="name_g" id="name_g" type="hidden" value="">
                    	<div>
              <input name="name_b1" id="name_b1" required placeholder="Имя" type="text">
                   		</div>
                    	<div>
              <input name="phone_b1" id="phone_b1" required placeholder="Телефон" type="text" >

              {literal}
              <script>
                function ValidPhone()
                {
                    var re = /^\d[\d\(\)\ -]{4,17}\d$/;
                    var myPhone = document.getElementById('phone_b1').value;
                    var valid = re.test(myPhone);
                    return valid;
                }
              </script> 
              {/literal}
                    	</div>
            <div>
              <input type="submit" value="Быстрый заказ" id="fsell_done">
                    	</div>
                	</div>

      $("#fsell_done").hover(
      function () {
var str_gname = $("span#layer_cart_product_title").text();
$("#name_g").val(str_gname);
      }
    );

link to full code: jsfiddle.net/8wagho7L
link to full code of processing script: jsfiddle.net/hkh7emuv

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Snytkin, 2015-11-03
@dima11221122

To transfer static data, which in our case is the price, you can use a hidden input in the form, for example:

<form>
...
<intput type="hidden" name="price" value="100" />
</form>

On the server, respectively, you need to "accept" this variable. This can be done with the line
PS I advise you to separate the logic of work from the presentation. In your case, transfer the processing of the payment form to a separate controller, in which, if successful, the corresponding view will be loaded.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question