DEV Community

Aveeva
Aveeva

Posted on

How to get HTML form data into PHP function Arguments?

The Business Logic is: If product is already purchased, upgrade the product

I have a customer input form to get information, along with some fields which should be auto populated based on what the customer chooses.

Screen Shot:

    https://i.stack.imgur.com/Fkyim.png

Note: Price and Shipping Weight are done with Ajax,

When we come to the shipping cost I am getting it from Magento, using a PHP function.

form :

     https://paste.ofcode.org/335FVUhpBGbazQtrcPLVQUs

PHP :

sp_cost.php

     https://paste.ofcode.org/hvG2sP9TW9CEPgMMuKXNuw

From the above code I am given the predefined value,

$results = getShippingEstimate('14419','1',"IN","642001");

How can i get country and zipcode from the user entry and return the shipping cost?

Top comments (1)

Collapse
 
aveeva profile image
Aveeva

Solved :

<script>
    $(document).ready(function(){
    $('#new').on('change',function(){

    var zip = $("#zip_postal_code").val();
    var country = $("#country").val();

    $.ajax({
    type: "POST",
    // url: "ajax_ship_cost_data.php",
    url: "sp_cost.php",
    dataType: "text",
    data: {zip_postal_code : zip, country: country},
    success: function(data)
    {
        // Check the output of ajax call on firebug console
         //console.log(data);
        $('#findata').html(data);
        $('#shipping_cost').val(data);

    }

});

});
});