Last active
December 23, 2020 19:37
-
-
Save malchata/4aeb36585cd312f33ae0cff736a79fcc to your computer and use it in GitHub Desktop.
Stateless component in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function SubscribeButton ($subscribed, $currentUserId, $userId, $className = null) { | |
if (!isset($userId) || !ctype_digit($userId) || $userId === $currentUserId) { | |
return ""; | |
} | |
$subscribeButtonClasses = "subscribe-button"; | |
if (!is_null($className)) { | |
$subscribeButtonClasses .= $className; | |
} | |
?> | |
<form method="POST" data-subscribed="<?php echo strval($subscribed); ?>" action="/subscribe"> | |
<button type="submit" class="<?php echo $subscribeButtonClasses; ?>"> | |
<?php echo $subscribed ? "Subscribed" : "Subscribe"; ?> | |
</button> | |
<input type="hidden" name="user-id" value="<?php echo strval($userId); ?>"> | |
</form> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment