How to write the value of the name attribute into a variable?

Depending on which button the user clicks, the form will be submitted with that and the value of the name attribute. How to enter the value of the name attribute into a variable if the value in it may be different?

<input name="" type="submit" value=" " />
<input name="" type="submit" value=" " />

How can I enter the word “Crackers” when I click on the variable $zakaz and if I click on the word “Chips”, enter it in the variable $zakaz.


Answer 1, authority 100%

When a form is submitted, the name of the submit that was clicked is sent. That is, in your case, you need a check

if(isset($_POST['']))
{
    // $_POST['_value']
}
elseif(isset($_POST['']))
{
    // $_POST['_value']
}

But in general, I do not advise naming variables in Cyrillic.


Answer 2, authority 100%

Remember that IE doesn’t allow you to manipulate the name attribute on the form, to change the attribute you have to hide the old input and create a new one with the new attributes. Maybe it’s better for you to make a checkbox “Order crackers/chips” and depending on which one is selected, show the corresponding input with the desired name attribute?


Answer 3, authority 100%

In order to send data to the server, your html code must have a form, or it must be handled by JavaScript, giving the data asynchronously!

<form name="zakaz_form" method="post" action="path\to_script.php">
<input name="suhari" ...>
<input name="chips" ...>
</form>

And already in the script, the variable named $_POST[‘suhari’] will have the desired value if you click on the button.