I have tried many different stack solutions to similar issues and none have worked. I have a HTML and PHP mixed together and if the clicks the download image link the PHP code checks whether the agree to Terms of Use before downloading. If they agreed and click the "Download Your Image" link, it should automatically download. If they have not agreed, an alert should pop up.
Here is the working HTML checkbox code:
<form method="post">
<input type="checkbox" name="terms" value="yes" id="agree" /> I have read and agree to the Terms and Conditions</br>
<button type="submit">test_post</button>
</form>
Here is the working HTML a href download link (with PHP inside to identify file):
<a href="<?php echo $new_image_with_overlay; ?>" download="<?php echo $new_image_name; ?>">Download Your Image</a>
Here is my PHP if statement (it works but not if I put the HTML a href inside):
<?php
if(isset($_POST['terms'])){
// the HTML a href or similar would go here to automatically download the image
} else {
// would like an alert presented to the user
echo "alert('Please indicate that you have read and agree to the Terms of Use')";
}
?>
The other option I tried which I couldn't get to work but would prefer would be having the "Download Your Image" a button instead of a link. Either would be suitable for this.