A
A
Alexander Kuznetsov2021-08-06 11:22:35
PHP
Alexander Kuznetsov, 2021-08-06 11:22:35

How to pass data from a website form to another page?

Good day everyone!
I don’t understand how it works and what I can do, help me in any way (:

There is such a form on the “product” page.
The product has a number of its own variables that must be transferred to the “basket” page after clicking on the booking button.

<form method="POST" action="<?php echo $link_address;?>">
    <input type="hidden" name="quantity" id="qntyt" value="1" min="1" />		
        <input type="hidden" name="hoursform" id="hoursf" value="<?php echo round( $pricing->hours ); ?>" min="1" />
        <input type="hidden" name="priceform" id="pricef" value="<?php echo $pricing->base; ?>" />
        <input type="hidden" name="addonform" id="addonf" value="<?php echo $addon->price; ?>" min="0" />
        <input type="submit" value="Забронировать" />
</form>


Before that, I tried to use the same form, but with a GET parameter, and everything seemed to be ok.
The parameters were transferred, but if you add two different products to the basket, then when you click the "book" button, the "prices and other parameters" of the first product in the basket are also updated and become like the first product and it looks like this:
Product 1 - Price 150r
When adding product 2 with a price of 70r
Product 1 also started to cost 70r

This is how I pulled out the parameters I needed on the "basket" page
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var foo = getParameterByName('hoursform');
var bar = getParameterByName('addonform'); 
var baz = getParameterByName('priceform'); 
var pricevalue = parseFloat(baz);


The question is this:
- How can I make sure that the form goes through the POST parameter and how to receive parameters from this POST request on the "landing page".
I understand that through POST I need to send data to a separate php page and from there on the "target" page to receive them.

But either the skis don’t go, or something else
Tell me what to see, read, think - because I won’t stick it in any way, but it seems that the question is trifling in general.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Viktorovich, 2021-08-06
@friendlix

Hello.
Everything is simple.
You paste it into your HTML:
(if you need to send it to another page, as you want, then use the action="/page.php" attribute and catch this request on another page)

<form method="POST" action=""> 
<label>Введите текст</label>
<input type="text" name="text" value="Просто текст">
<button type="submit" class="btn btn-success">Отправить текст</button>
</form>

After this form, you need to catch the data using PHP.
Let's write a handler with you.
<?php

if(!empty($_POST['text'])){
//тут уже у тебя будет то, что ты хотел, например, как мы указали, текст в форме, он выведется тут
//можешь проверишь просто: var_dump($_POST['text']);
//Дальше уже делай что тебе нужно, сохраняй в базу данных или куда ты хочешь, не забудь про 
//фильтрации
$text = $_POST['text']; // не забудь про проверки  и фильтрации.
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question