John Davidson

php - Wordpress: Is it possible to have 2 forms on the same page that use $index and $value for input fields?


I have two checkbox forms on the same page. When they are both there, the second form will not work. I'm wondering if there is a way to have both on the same page with them both needing the $index of the input.

The input fields are similar to this (the other is unchecked):

echo "<input type='checkbox' name='check[]' value='$index' onChange='this.form.submit()' checked='checked'>";
echo "<input type='hidden' name='itemDELETE$index' value='$bookID'>";

This is the other

echo "<input type='checkbox' name='checkbox[]' value='$index' onChange='this.form.submit()'>";
echo "<input type='hidden' name='itemADD$index' value='$bookID'>";

And the data is stored like:

$value = $_POST["check"][0];
$toDELETE = $_POST["itemDELETE" . $value];


$value = $_POST["checkbox"][0];
$toADD = $_POST["itemADD" . $value];

I have tried renaming $value but the issue lies in the $index on the input fields.

They are outputting correctly, but the second one will not store the value properly in it's variable, whereas the first does. The second is the delete one.

When I remove the first forms functionality, the second form works. But when I add it back, the second one stops working. Not picking up on the itemDELETE $value

If I manually put the value in like this "itemDELETE0" instead of ["itemDELETE" . $value]it works. But I need the $value to picked up on since it's a foreach loop.

My Answer:

Rate this post

4 of 5 based on 9850 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us