1

I am creating a kiosk where people can register for sessions. Each session time slot is displayed in a button with the number of seats remaining. When the capacity reaches 0, text displays under the time slot on the button that says "no seats remaining".

How can i disable the button based on a value in my PHP array, so people are unable to click it?

<button type="submit" name="DS1" value="1">
    <h4>10:30 - 11:15</h4>
    <h5><?php if ($result[0]['capacity'] > "0") {
            echo $result[0]['capacity'];
            echo " Seats Remaining";
        } else {
            echo "This Session is Full!";
        } ?></h5>
</button>

3 Answers 3

2
<button type="submit" name="DS1" value="1" <?php if($result[0]['capacity'] > "0"){echo 'disabled'; } ?>><h4>10:30 - 11:15</h4> <h5><?php if($result[0]['capacity'] > "0"){echo $result[0]['capacity']; echo " Seats Remaining";} else {echo "This Session is Full!";}?></h5></button>

Should work, this adds a property disabled to the button. It can't be pressed if this property is present

In your case it would be best to make an if-block to make it more readable and easier to adjust:

<?php if($result[0]['capacity'] > "0") : ?>
  <button type="submit" name="DS1" value="1">
    <h4>10:30 - 11:15</h4>
    <h5><?php echo($result[0]['capacity']); ?> Seats remaining</h5>
  </button>
<?php else : ?>
  <button type="submit" name="DS1" value="1" disabled>
    <h4>10:30 - 11:15</h4>
    <h5>This Session is Full</h5>
  </button>
<?php endif; ?>
Sign up to request clarification or add additional context in comments.

Comments

1

The first if checks if the value is 0. If it is it will attach the disabled property to the button. Otherwise it will show the non-disabled button.

This is more of clean solution I feel anyway.

if ($result[0]['capacity'] == "0") {
    <button type="submit" name="DS1" value="1" disabled>Your Button Display Value</button>
} else {
    <button type="submit" name="DS1" value="1">Your Button Display Value</button>
}

Comments

1

I would wrap the button itself inside the seats available, so as to not confuse the user with a button at all. So:

<?php
if($result[0]['capacity'] > "0")
{
    $seatsRemaining = $result[0]['capacity'];
    $buttonDisp = "<button type='submit' name='DS1' value='1'><h4>10:30 - 11:15</h4> <h5>$seatsRemaining Seats Remaining</h5></button>";
}
else
{
    $buttonDisp = "This Session is Full!";
}

echo $buttonDisp;
?>

Now a user won't see a button to press, and instead see your message.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.