I know variations of this question have been asked, but this is a different question than what I have been able to find. I am building a dynamic list of subscriptions on a single page with information from the database and each subscription has a "cancel" button that uses some form data to make that cancellation happen.
Here is an example of the cancel button on each table row:
<form method="post" action="">
<?php $token = $_SESSION['token'] = md5( session_id() . time(). rand() ); ?>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<input type="hidden" name="sg_subscriptionID" value="<?php echo $subscriptionID; ?>" />
<input type="hidden" name="sg_postID" value="<?php echo $post->ID; ?>" />
<input type="submit" class="button" name="submit" value="Cancel" />
</form>
To process the form, at the top of the file I am using <?php if(isset($_POST['submit']) {} ?>
This is not working when there are multiple forms on the page, I suspect because it can't differentiate between form data based on the input name "submit".
There isn't a definitive number of forms to be created, so I can't simply just have "submit1", "submit2". I can add a number dynamically using $count, but how would I check for an array of dynamic numbers in my form handling script?
I appreciate any suggestions for a possible better approach. I am trying to steer clear of ajax if at all possible.
<input type="hidden" name="token" value="<?php echo $token; ?>" />since you already have$_SESSION['token']you can pick up the value any where else on your site except your posting the form to a different server.