SHOW:
|
|
- or go back to the newest paste.
| 1 | <form id="myform" action="http://ymlp.com/subscribe.php?id=<?= $userid; ?" type="POST"> | |
| 2 | <input type="hidden" id="userid" name="userid" value="<?= $userid; ?>"> | |
| 3 | <input type="checkbox" id="accept" name="accept" value="accept"> | |
| 4 | <input type="submit" name="submit" id="submit" value="submit"> | |
| 5 | </form> | |
| 6 | <script | |
| 7 | src="https://code.jquery.com/jquery-3.3.1.min.js" | |
| 8 | integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" | |
| 9 | crossorigin="anonymous"></script> | |
| 10 | <script> | |
| 11 | $('#submit').on('click', function(e){
| |
| 12 | - | var userid = $('#userid').val();
|
| 12 | + | |
| 13 | - | $.ajax({
|
| 13 | + | // check if checkbox is checked |
| 14 | - | type: "POST", |
| 14 | + | if ($('#accept').is('checked')) {
|
| 15 | - | url: "myphp.php", |
| 15 | + | var userid = $('#userid').val();
|
| 16 | - | data: {'userid' : userid},
|
| 16 | + | $.ajax({
|
| 17 | - | success: function(data) {
|
| 17 | + | type: "POST", |
| 18 | - | if ($.trim(data) == 'success') {
|
| 18 | + | url: "myphp.php", |
| 19 | - | $('#myform').submit();
|
| 19 | + | data: {'userid' : userid},
|
| 20 | success: function(data) {
| |
| 21 | - | } |
| 21 | + | if ($.trim(data) == 'success') {
|
| 22 | - | }); |
| 22 | + | $('#myform').submit();
|
| 23 | } | |
| 24 | } | |
| 25 | }); | |
| 26 | } | |
| 27 | }); | |
| 28 | </script> |