Home>

I'm new to HTML, but I generate a button for each loop in foreach on HTML, store the element in hidden, and
I want to post when the button is pressed.
For example, if $value holds the following array
value = [order_no = 1, name = a, kind = 1, flag = 1],
[order_no = 2, name = b, kind = 2, flag = 2],
[order_no = 3, name = c, kind = 3, flag = 3]
If i press the "a" button, order_no = 1, name = a, kind = 1, flag = 1
If i press the "b" button, order_no = 2, name = b, kind = 2, flag = 2
If i press the "c" button, order_no = 3, name = c, kind = 3, flag = 3
I want to be posted.

I want to store order_no, name, kind, flag for each loop.
It will be rewritten at the last line of the pool.
In the above example, with all the "a", "b", and "c" buttons
order_no = 3, name = c, kind = 3, flag = 3
Will be posted.

Corresponding source code
<? php foreach ($value as $key =>$item):?>
              <input type = "hidden" name = "order_no" value = "<? = $item [" order_no "];?>">
              <input type = "hidden" name = "name" value = "<? = $item [" name "];?>">
              <input type = "hidden" name = "kind" value = "<? = $item ["kind "];?>">
              <input type = "hidden" name = "flag" value = "<? = $item ["flag "];?>">
              <button type = "submit"><? = $item ["name"];?></button>
<? php endforeach;?>
What I tried

I searched for a way to change the hidden name for each loop.
If possible, I want to realize the name without changing it for each loop.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here. $

  • Answer # 1

    If possible, I want to realize the name without changing it for each loop.

    If so, per loop (per button)formDivide,
    There is a hand.
    Currently,foreachOn the outside offormI think there is a tag,
    ItforeachIt feels like putting it inside.

    Alternatively, hideden should be only one set
    Hidden in JS, depending on the button pressedvalueAfter changing
    Like submit.

  • Answer # 2

    If you want to send different parameters with multiple contents for each button
    It is realistic to separate the forms.
    If not, you will need to replace the parameters with js.