I may be going about this completely the wrong way but bear with me… I have a long guestlist that is automatically populated using a foreach
table.
I would like to put a ‘No Show’ button on this guestlist so that without being admin the host of the event can click (client side) “No Show” and update the ticket (custom post) meta to State: ‘noshow’
A lot of the examples I have found mean making a new .php page for the submit button to link to and run the code [obviously because it is server side language] – the first problem is then, once they have clicked the submit button, it goes to a blank page (having no real HTML output) rather than returning to their event… This isn’t such a big problem – I can put a redirect in I suppose but seems a bit clunky.
The second problem is also that many of these examples don’t take into account A) Multiple Submit Buttons that have to be automatically produced B) Different PHP code to be triggered for each one…
Here is the jist of what I need doing below:
<form onsubmit="return confirm('Do you want to mark <?php echo $FullName ?> as a 'No Show' - this cannot be undone unless you are an admin');" method="post" action="<?php HELP ?>">
<input name="NoShow<?php echo $IDuser?>" type="submit" value="No Show" class="button" /> //$IDuser is their user ID to give the values something different on the page. Could also be ticket [post] numbers?
</form>
Now on the server side I need something like this to run:
$tixID = $ticket['id']; //This gets the ticket [custom post] ID number
$StateKey = state; //This is the meta_key that needs changing
$NoShowing = noshow; //This is what it needs to change to.
update_post_meta($tixID , $StateKey , $NoShowing ); #This is the code to change the State: to No Show
?>
So I gather I need to use something along the lines of
if(isset($_POST['SUBMIT-BUTTON'])) {
some_function_called_here();
}
But this is fixed and is looking out for a certain name – It would be physically impossible for me to type out the different submit button names as it would be changing individual tickets – of which about 6,000 have already been sold on the site… Also the function called would have to be unique to the button that called it.
Any shining light would be great as I feel like I’m going round in circles with some of these blog posts.
EDIT:
Sorry – for clarification.
What I need to happen is…
-
Trigger – User presses one button in a list of buttons client side. It is generated in a table using php and a foreach that lists tickets bought for that event.
<input name="noshow<?php echo $ticketID ?>" type="submit" value="No Show" class="button" />
-
Action – Each particular button corresponds to a particular ticket, once the button is clicked for that ticket it runs the code to edit that ticket post meta data, server side.
update_post_meta($ticketID , 'state' , 'noshow' );
This updates the keyState:
tonoshow
-
Result – Page is reloaded and you remain on the same event page
Here’s a visual example of the screenshot
Instead of redirecting to a new page, you can use the one you’re already on with basic logic similar to this:
Perhaps you will have a form for each button, or a single form, that part is a generic PHP/HTML question beyond the scope of this site ( stack overflow would be the appropriate place )