1

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...

  1. 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" />

  2. 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 key State: to noshow

  3. Result - Page is reloaded and you remain on the same event page

Here's a visual example of the screenshot

Screenshot Example of scenario

  • Can you make some modifications to your wording, I'm having trouble comprehending exactly why your wanting to do? If you can set it out in sections e.g."what Im trying to do, what I've done, what I expected to happen, whats actually happening" – Tom J Nowell Mar 21 '14 at 13:26
  • @TomJNowell Sorry - yes - I've added some clearer steps at the bottom to accompany my ramblings – Bysander Mar 21 '14 at 13:40
  • 1
    If update_post_meta is all what you need, you can do it with Ajax I guess, here is how it would go, get ticket id on the current screen as hidden input, on button click send a Ajax request, validate it and update meta key, on success update current screen with js, no refresh at all. I'm suggesting on basis of what i got from your question – sven Mar 21 '14 at 14:01
2

Instead of redirecting to a new page, you can use the one you're already on with basic logic similar to this:

if ( !empty( $_POST['ticket_action'] && ( $_POST['ticket_action'] == 'noshow' ) ) {
    $ticket_post_id = $_POST['ticket_post_id'];
    ... you probably want to check if the user is logged in or check for a valid nonce here ...
    // do whatever it is with the ticket post that you wanted to do here
    ?>
    <p>Success!! Or Error, or some other message dependent on what happened in form processing</p>
    <?php
}
 .... later on ...
    ?>
    <form method="post" action="">
        <input type="hidden" name="ticket_post_id" value="<?php the_ID();?>" />
        ... you should probably put a nonce here too, search this site for examples and explanations on what they are ...
        <input type="hidden" name="ticket_action" value="noshow" />
        <input type="submit" value="no show" />
    </form>
    <?php

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 )

  • Hi, its generated off a wordpress page using custom posts as tickets. I just have no idea how to dynamically listen for each button to then generate the php to alter the correct ticket post... I'll try the regular stack exchange if no joy here today – Bysander Mar 21 '14 at 13:44
  • You'll want a form + button for each post with a hidden input field for the post ID, and a button input. As for the what to do once the form has been submitted, you've not said what you want to do, which would be another question ( like how do I delete a post in code? or How do I trash a post in code? ) but at least now you know where to put it – Tom J Nowell Mar 21 '14 at 14:08
  • I've modified my answer, it should be a little more informative. Keep in mind that the end form would go in your post loop and there would be more than one of them – Tom J Nowell Mar 21 '14 at 14:13
  • Hey, yes I was being a bit of an idiot - I got caught up on trying to do it with the single submit button - it sounds stupid but it never occurred to me to put a hidden input in - that's the problem with teaching yourself coding... I also didn't put any nonces in - simply because (correct me if i'm wrong) it seems it is a security measure to stop erroneous or malicious use of that form, but that part of the page is not viewable to anyone except if you are the event host or an admin. I just didn't want to make all event hosts admins on the site for obvious reasons. Thanks for all your help – Bysander Mar 21 '14 at 16:06
  • if I put in a form on a completely different website or a piece of JS and told one of your admins to visit that page, I could make their browser click a no show button automatically, against their will, the same way I can put an image in a blogpost whos URL is your blogs logout URL, etc etc, thats why we have nonces – Tom J Nowell Mar 21 '14 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.